Skip to content

Extended fix for generics + test #2335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2016
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