Skip to content

Commit 9a52273

Browse files
authored
Fix PEP 695 type alias with mix of type args (PEP 696) (python#18919)
Fix an issue where TypeVar defaults wouldn't be applied to PEP 695 type aliases. Fixes python#18921
1 parent df60055 commit 9a52273

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

mypy/semanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5591,7 +5591,7 @@ def visit_type_alias_stmt(self, s: TypeAliasStmt) -> None:
55915591
self.msg.unimported_type_becomes_any("Type alias target", res, s)
55925592
res = make_any_non_unimported(res)
55935593
eager = self.is_func_scope()
5594-
if isinstance(res, ProperType) and isinstance(res, Instance) and not res.args:
5594+
if isinstance(res, ProperType) and isinstance(res, Instance):
55955595
fix_instance(res, self.fail, self.note, disallow_any=False, options=self.options)
55965596
alias_node = TypeAlias(
55975597
res,

test-data/unit/check-python313.test

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def func_a1(
219219
reveal_type(b) # N: Revealed type is "builtins.dict[builtins.float, builtins.str]"
220220
reveal_type(c) # N: Revealed type is "builtins.dict[builtins.float, builtins.float]"
221221
reveal_type(d) # N: Revealed type is "builtins.dict[builtins.int, builtins.str]"
222-
[builtins fixtures/tuple.pyi]
222+
[builtins fixtures/dict.pyi]
223223
[typing fixtures/typing-full.pyi]
224224

225225
[case testPEP695TypeParameterDefaultTypeAlias2]
@@ -255,3 +255,22 @@ def func_c1(
255255

256256
[builtins fixtures/tuple.pyi]
257257
[typing fixtures/typing-full.pyi]
258+
259+
[case testPEP695TypeParameterDefaultTypeAlias4]
260+
# flags: --disallow-any-generics
261+
class A[L = int, M = str]: ...
262+
TD1 = A[float]
263+
type TD2 = A[float]
264+
265+
def func_d1(
266+
a: TD1,
267+
b: TD1[float], # E: Bad number of arguments for type alias, expected 0, given 1
268+
c: TD2,
269+
d: TD2[float], # E: Bad number of arguments for type alias, expected 0, given 1
270+
) -> None:
271+
reveal_type(a) # N: Revealed type is "__main__.A[builtins.float, builtins.str]"
272+
reveal_type(b) # N: Revealed type is "__main__.A[builtins.float, builtins.str]"
273+
reveal_type(c) # N: Revealed type is "__main__.A[builtins.float, builtins.str]"
274+
reveal_type(d) # N: Revealed type is "__main__.A[builtins.float, builtins.str]"
275+
[builtins fixtures/tuple.pyi]
276+
[typing fixtures/typing-full.pyi]

0 commit comments

Comments
 (0)