Skip to content

Commit d1c6904

Browse files
Don't expand PEP 695 aliases when checking node fullnames (#19699)
Fixes #19698
1 parent 657bdd8 commit d1c6904

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

mypy/semanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7678,7 +7678,7 @@ def refers_to_fullname(node: Expression, fullnames: str | tuple[str, ...]) -> bo
76787678
return False
76797679
if node.fullname in fullnames:
76807680
return True
7681-
if isinstance(node.node, TypeAlias):
7681+
if isinstance(node.node, TypeAlias) and not node.node.python_3_12_type_alias:
76827682
return is_named_instance(node.node.target, fullnames)
76837683
return False
76847684

test-data/unit/check-python312.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,3 +2095,19 @@ from dataclasses import dataclass
20952095
class Test[*Ts, R]:
20962096
a: Callable[[*Ts], R]
20972097
[builtins fixtures/dict.pyi]
2098+
2099+
[case testPEP695AliasDoesNotReferToFullname]
2100+
# https://github.com/python/mypy/issues/19698
2101+
from typing import TypeAliasType
2102+
type D = dict
2103+
type T = type
2104+
type TA = TypeAliasType
2105+
2106+
D() # E: "TypeAliasType" not callable
2107+
X = TA("Y") # E: "TypeAliasType" not callable
2108+
2109+
x: object
2110+
if T(x) is str: # E: "TypeAliasType" not callable
2111+
reveal_type(x) # N: Revealed type is "builtins.object"
2112+
[builtins fixtures/tuple.pyi]
2113+
[typing fixtures/typing-full.pyi]

0 commit comments

Comments
 (0)