Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 5 additions & 3 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1374,9 +1374,11 @@ def visit_reveal_type_expr(self, expr: RevealTypeExpr) -> Type:
def visit_type_application(self, tapp: TypeApplication) -> Type:
"""Type check a type application (expr[type, ...])."""
tp = self.accept(tapp.expr)
if not isinstance(tp, CallableType):
return AnyType()
return self.apply_generic_arguments(tp, tapp.types, tapp)
if isinstance(tp, CallableType):
return self.apply_generic_arguments(tp, tapp.types, tapp)
if isinstance(tp, Overloaded):
return self.apply_generic_arguments2(tp, tapp.types, tapp)
return AnyType()

def visit_type_alias_expr(self, alias: TypeAliasExpr) -> Type:
return AnyType()
Expand Down
5 changes: 5 additions & 0 deletions test-data/unit/check-generics.test
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,11 @@ Alias[int](1)
Alias[int]("a") # E: Argument 1 to "Node" has incompatible type "str"; expected "int"
[out]

[case testTypeApplicationCrash]
type[int] # this was crashing, see #2302 (comment) # E: Type application targets a non-generic function or class
[out]


-- Multiple assignment with lists
-- ------------------------------

Expand Down