Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,10 +956,13 @@ def verify_decorator(
def verify_typealias(
stub: nodes.TypeAlias, runtime: MaybeMissing[Any], object_path: List[str]
) -> Iterator[Error]:
stub_target = mypy.types.get_proper_type(stub.target)
if isinstance(runtime, Missing):
# ignore type aliases that don't have a runtime counterpart
yield Error(
object_path, "is not present at runtime", stub, runtime,
stub_desc=f"Type alias for {stub_target}"
)
return
stub_target = mypy.types.get_proper_type(stub.target)
if isinstance(stub_target, mypy.types.Instance):
yield from verify(stub_target.type, runtime, object_path)
return
Expand Down
12 changes: 12 additions & 0 deletions mypy/test/teststubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,18 @@ class Y: ...
runtime="A = (int, str)",
error="A",
)
# Error if an alias isn't present at runtime...
yield Case(
stub="B = str",
runtime="",
error="B"
)
# ... but only if the alias isn't private
yield Case(
stub="_C = int",
runtime="",
error=None
)

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