Skip to content

Commit d8c9a81

Browse files
ilevkivskyigvanrossum
authored andcommitted
Extended fix for generics + test (#2335)
1 parent fc94151 commit d8c9a81

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

mypy/checkexpr.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,9 +1374,11 @@ def visit_reveal_type_expr(self, expr: RevealTypeExpr) -> Type:
13741374
def visit_type_application(self, tapp: TypeApplication) -> Type:
13751375
"""Type check a type application (expr[type, ...])."""
13761376
tp = self.accept(tapp.expr)
1377-
if not isinstance(tp, CallableType):
1378-
return AnyType()
1379-
return self.apply_generic_arguments(tp, tapp.types, tapp)
1377+
if isinstance(tp, CallableType):
1378+
return self.apply_generic_arguments(tp, tapp.types, tapp)
1379+
if isinstance(tp, Overloaded):
1380+
return self.apply_generic_arguments2(tp, tapp.types, tapp)
1381+
return AnyType()
13801382

13811383
def visit_type_alias_expr(self, alias: TypeAliasExpr) -> Type:
13821384
return AnyType()

test-data/unit/check-generics.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,11 @@ Alias[int](1)
500500
Alias[int]("a") # E: Argument 1 to "Node" has incompatible type "str"; expected "int"
501501
[out]
502502

503+
[case testTypeApplicationCrash]
504+
type[int] # this was crashing, see #2302 (comment) # E: Type application targets a non-generic function or class
505+
[out]
506+
507+
503508
-- Multiple assignment with lists
504509
-- ------------------------------
505510

0 commit comments

Comments
 (0)