@@ -3097,31 +3097,18 @@ def visit_raise_stmt(self, s: RaiseStmt) -> None:
3097
3097
def type_check_raise (self , e : Expression , s : RaiseStmt ,
3098
3098
optional : bool = False ) -> None :
3099
3099
typ = get_proper_type (self .expr_checker .accept (e ))
3100
- if isinstance (typ , TypeType ):
3101
- if isinstance (typ .item , AnyType ):
3102
- return
3103
- typ = typ .item
3104
- if isinstance (typ , FunctionLike ):
3105
- if typ .is_type_obj ():
3106
- # Cases like "raise/from ExceptionClass".
3107
- typeinfo = typ .type_object ()
3108
- base = self .lookup_typeinfo ('builtins.BaseException' )
3109
- if base in typeinfo .mro or typeinfo .fallback_to_any :
3110
- # Good!
3111
- return
3112
- # Else fall back to the checks below (which will fail).
3113
- if isinstance (typ , TupleType ) and self .options .python_version [0 ] == 2 :
3100
+ exc_type = self .named_type ('builtins.BaseException' )
3101
+ expected_type = UnionType ([exc_type , TypeType (exc_type )])
3102
+ if optional :
3103
+ expected_type .items .append (NoneType ())
3104
+ if self .options .python_version [0 ] == 2 :
3114
3105
# allow `raise type, value, traceback`
3115
3106
# https://docs.python.org/2/reference/simple_stmts.html#the-raise-statement
3116
3107
# TODO: Also check tuple item types.
3117
- if len (typ .items ) in (2 , 3 ):
3118
- return
3119
- if isinstance (typ , Instance ) and typ .type .fallback_to_any :
3120
- # OK!
3121
- return
3122
- expected_type = self .named_type ('builtins.BaseException' ) # type: Type
3123
- if optional :
3124
- expected_type = UnionType ([expected_type , NoneType ()])
3108
+ any_type = AnyType (TypeOfAny .implementation_artifact )
3109
+ tuple_type = self .named_type ('builtins.tuple' )
3110
+ expected_type .items .append (TupleType ([any_type , any_type ], tuple_type ))
3111
+ expected_type .items .append (TupleType ([any_type , any_type , any_type ], tuple_type ))
3125
3112
self .check_subtype (typ , expected_type , s , message_registry .INVALID_EXCEPTION )
3126
3113
3127
3114
def visit_try_stmt (self , s : TryStmt ) -> None :
0 commit comments