diff --git a/mypy/stubutil.py b/mypy/stubutil.py index 3f917ca7665d..c11843c57f2a 100644 --- a/mypy/stubutil.py +++ b/mypy/stubutil.py @@ -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: diff --git a/test-data/unit/stubgen.test b/test-data/unit/stubgen.test index e64c9c66d65d..0801d9a27011 100644 --- a/test-data/unit/stubgen.test +++ b/test-data/unit/stubgen.test @@ -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: ...