Skip to content

Commit 3e52d0c

Browse files
authored
stubgen: do not include mypy generated symbols (#18137)
Addresses part of #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.
1 parent 3b63891 commit 3e52d0c

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

mypy/stubutil.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,8 @@ def is_not_in_all(self, name: str) -> bool:
832832
return False
833833

834834
def is_private_name(self, name: str, fullname: str | None = None) -> bool:
835+
if "__mypy-" in name:
836+
return True # Never include mypy generated symbols
835837
if self._include_private:
836838
return False
837839
if fullname in self.EXTRA_EXPORTED:

test-data/unit/stubgen.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4508,3 +4508,21 @@ class C3[T3 = int]: ...
45084508
class C4[T4: int | float = int](list[T4]): ...
45094509

45104510
def f5[T5 = int]() -> None: ...
4511+
4512+
[case testIgnoreMypyGeneratedMethods_semanal]
4513+
# flags: --include-private --python-version=3.13
4514+
from typing_extensions import dataclass_transform
4515+
4516+
# TODO: preserve dataclass_transform decorator
4517+
@dataclass_transform()
4518+
class DCMeta(type): ...
4519+
class DC(metaclass=DCMeta):
4520+
x: str
4521+
4522+
[out]
4523+
class DCMeta(type): ...
4524+
4525+
class DC(metaclass=DCMeta):
4526+
x: str
4527+
def __init__(self, x) -> None: ...
4528+
def __replace__(self, *, x) -> None: ...

0 commit comments

Comments
 (0)