Skip to content

Commit

Permalink
stubgen: do not include mypy generated symbols (python#18137)
Browse files Browse the repository at this point in the history
Addresses part of python#18081

stubgen still does not handle dataclass transforms correctly but with
this change we make sure to never include private mypy generated symbols
in the stubs.
  • Loading branch information
hamdanal authored Nov 14, 2024
1 parent 3b63891 commit 3e52d0c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mypy/stubutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,8 @@ def is_not_in_all(self, name: str) -> bool:
return False

def is_private_name(self, name: str, fullname: str | None = None) -> bool:
if "__mypy-" in name:
return True # Never include mypy generated symbols
if self._include_private:
return False
if fullname in self.EXTRA_EXPORTED:
Expand Down
18 changes: 18 additions & 0 deletions test-data/unit/stubgen.test
Original file line number Diff line number Diff line change
Expand Up @@ -4508,3 +4508,21 @@ class C3[T3 = int]: ...
class C4[T4: int | float = int](list[T4]): ...

def f5[T5 = int]() -> None: ...

[case testIgnoreMypyGeneratedMethods_semanal]
# flags: --include-private --python-version=3.13
from typing_extensions import dataclass_transform

# TODO: preserve dataclass_transform decorator
@dataclass_transform()
class DCMeta(type): ...
class DC(metaclass=DCMeta):
x: str

[out]
class DCMeta(type): ...

class DC(metaclass=DCMeta):
x: str
def __init__(self, x) -> None: ...
def __replace__(self, *, x) -> None: ...

0 comments on commit 3e52d0c

Please sign in to comment.