Skip to content

Commit 6179c94

Browse files
authored
🔨 only delete __init__.pyi when "unstubbing" (#570)
1 parent 7f0f493 commit 6179c94

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

‎tool/stubtest.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ def __check_simd() -> None:
7171

7272
def __commit_pyi_genocide_for_mypy() -> None:
7373
"""
74-
Remove the ``py.typed`` and all ``*.pyi`` files from the installed numpy package.
74+
Remove all ``__init__.pyi`` files from the installed numpy package.
75+
76+
This works around https://github.com/python/mypy/issues/18997 on `mypy<1.16.0`.
7577
7678
Raises
7779
------
@@ -82,15 +84,9 @@ def __commit_pyi_genocide_for_mypy() -> None:
8284
if not package.is_dir():
8385
raise NotADirectoryError(f"{package} does not exist")
8486

85-
py_typed = package / "py.typed"
86-
if py_typed.is_file():
87-
py_typed.unlink()
88-
if VERBOSE:
89-
print(f"deleted {py_typed} (1)")
90-
91-
graveyard_size = sum(not pyi.unlink() for pyi in package.rglob("*.pyi")) # type: ignore[func-returns-value]
87+
graveyard_size = sum(not pyi.unlink() for pyi in package.rglob("__init__.pyi")) # type: ignore[func-returns-value]
9288
if VERBOSE and graveyard_size:
93-
print(f"deleted {package}/**/*.pyi ({graveyard_size})\n")
89+
print(f"deleted {graveyard_size} __init__.pyi from {package}\n")
9490

9591

9692
def _allowlists() -> list[str]:

‎tool/unstub.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""
2-
Delete all `.pyi` files in the `numpy` site-packages directory.
2+
Delete all `__init__.pyi` files in the `numpy` site-packages directory.
3+
4+
This is a workaround for https://github.com/python/mypy/issues/18997 on `mypy<1.16.0`
35
46
Run with `uv run tool/unstub.py`.
57
"""
@@ -10,6 +12,5 @@
1012
package = Path(sysconfig.get_paths()["purelib"]) / "numpy"
1113
assert package.is_dir(), package
1214

13-
(package / "py.typed").unlink(missing_ok=True)
14-
bodycount = sum(not pyi.unlink() for pyi in package.rglob("*.pyi")) # type: ignore[func-returns-value]
15-
print(f"{bodycount} files deleted from {package.relative_to(Path.cwd())}/**/*.pyi")
15+
bodycount = sum(not pyi.unlink() for pyi in package.rglob("__init__.pyi")) # type: ignore[func-returns-value]
16+
print(f"{bodycount} files deleted from {package.relative_to(Path.cwd())}")

0 commit comments

Comments
 (0)