diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index 226214d85343..485e0b75ffa0 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -1374,6 +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 = cast(CallableType, self.accept(tapp.expr)) + if isinstance(tp, AnyType): + return AnyType() + if not hasattr(tp, 'variables'): + self.chk.fail('Type application targets invalid expression', tapp) + return AnyType() return self.apply_generic_arguments(tp, tapp.types, tapp) def visit_type_alias_expr(self, alias: TypeAliasExpr) -> Type: