Skip to content

Commit

Permalink
Stubtest: handle name-mangling edge cases better (#14596)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood authored Feb 3, 2023
1 parent 523c381 commit 11739e4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def verify_typeinfo(
for entry in sorted(to_check):
mangled_entry = entry
if entry.startswith("__") and not entry.endswith("__"):
mangled_entry = f"_{stub.name}{entry}"
mangled_entry = f"_{stub.name.lstrip('_')}{entry}"
stub_to_verify = next((t.names[entry].node for t in stub.mro if entry in t.names), MISSING)
assert stub_to_verify is not None
try:
Expand Down
43 changes: 43 additions & 0 deletions mypy/test/teststubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,49 @@ def __mangle_bad(self, text): pass
""",
error="X.__mangle_bad",
)
yield Case(
stub="""
class Klass:
class __Mangled1:
class __Mangled2:
def __mangle_good(self, text: str) -> None: ...
def __mangle_bad(self, number: int) -> None: ...
""",
runtime="""
class Klass:
class __Mangled1:
class __Mangled2:
def __mangle_good(self, text): pass
def __mangle_bad(self, text): pass
""",
error="Klass.__Mangled1.__Mangled2.__mangle_bad",
)
yield Case(
stub="""
class __Dunder__:
def __mangle_good(self, text: str) -> None: ...
def __mangle_bad(self, number: int) -> None: ...
""",
runtime="""
class __Dunder__:
def __mangle_good(self, text): pass
def __mangle_bad(self, text): pass
""",
error="__Dunder__.__mangle_bad",
)
yield Case(
stub="""
class _Private:
def __mangle_good(self, text: str) -> None: ...
def __mangle_bad(self, number: int) -> None: ...
""",
runtime="""
class _Private:
def __mangle_good(self, text): pass
def __mangle_bad(self, text): pass
""",
error="_Private.__mangle_bad",
)

@collect_cases
def test_mro(self) -> Iterator[Case]:
Expand Down

0 comments on commit 11739e4

Please sign in to comment.