198198from mypy .types import (
199199 ANY_STRATEGY ,
200200 MYPYC_NATIVE_INT_NAMES ,
201+ NOT_IMPLEMENTED_TYPE_NAMES ,
201202 OVERLOAD_NAMES ,
202203 AnyType ,
203204 BoolTypeQuery ,
@@ -4449,7 +4450,7 @@ def infer_variable_type(
44494450 # partial type which will be made more specific later. A partial type
44504451 # gets generated in assignment like 'x = []' where item type is not known.
44514452 if name .name != "_" and not self .infer_partial_type (name , lvalue , init_type ):
4452- self .msg .need_annotation_for_var (name , context , self .options . python_version )
4453+ self .msg .need_annotation_for_var (name , context , self .options )
44534454 self .set_inference_error_fallback_type (name , lvalue , init_type )
44544455 elif (
44554456 isinstance (lvalue , MemberExpr )
@@ -4459,7 +4460,7 @@ def infer_variable_type(
44594460 and not is_same_type (self .inferred_attribute_types [lvalue .def_var ], init_type )
44604461 ):
44614462 # Multiple, inconsistent types inferred for an attribute.
4462- self .msg .need_annotation_for_var (name , context , self .options . python_version )
4463+ self .msg .need_annotation_for_var (name , context , self .options )
44634464 name .type = AnyType (TypeOfAny .from_error )
44644465 else :
44654466 # Infer type of the target.
@@ -4656,9 +4657,7 @@ def check_simple_assignment(
46564657 rvalue , type_context = lvalue_type , always_allow_any = always_allow_any
46574658 )
46584659 if not is_valid_inferred_type (rvalue_type , self .options ) and inferred is not None :
4659- self .msg .need_annotation_for_var (
4660- inferred , context , self .options .python_version
4661- )
4660+ self .msg .need_annotation_for_var (inferred , context , self .options )
46624661 rvalue_type = rvalue_type .accept (SetNothingToAny ())
46634662
46644663 if (
@@ -4976,10 +4975,7 @@ def check_return_stmt(self, s: ReturnStmt) -> None:
49764975 )
49774976 # Treat NotImplemented as having type Any, consistent with its
49784977 # definition in typeshed prior to python/typeshed#4222.
4979- if (
4980- isinstance (typ , Instance )
4981- and typ .type .fullname == "builtins._NotImplementedType"
4982- ):
4978+ if isinstance (typ , Instance ) and typ .type .fullname in NOT_IMPLEMENTED_TYPE_NAMES :
49834979 typ = AnyType (TypeOfAny .special_form )
49844980
49854981 if defn .is_async_generator :
@@ -5138,7 +5134,11 @@ def type_check_raise(self, e: Expression, s: RaiseStmt, optional: bool = False)
51385134 # https://github.com/python/mypy/issues/11089
51395135 self .expr_checker .check_call (typ , [], [], e )
51405136
5141- if isinstance (typ , Instance ) and typ .type .fullname == "builtins._NotImplementedType" :
5137+ if (isinstance (typ , Instance ) and typ .type .fullname in NOT_IMPLEMENTED_TYPE_NAMES ) or (
5138+ isinstance (e , CallExpr )
5139+ and isinstance (e .callee , RefExpr )
5140+ and e .callee .fullname == "builtins.NotImplemented"
5141+ ):
51425142 self .fail (
51435143 message_registry .INVALID_EXCEPTION .with_additional_msg (
51445144 '; did you mean "NotImplementedError"?'
@@ -7680,7 +7680,7 @@ def enter_partial_types(
76807680 var .type = NoneType ()
76817681 else :
76827682 if var not in self .partial_reported and not permissive :
7683- self .msg .need_annotation_for_var (var , context , self .options . python_version )
7683+ self .msg .need_annotation_for_var (var , context , self .options )
76847684 self .partial_reported .add (var )
76857685 if var .type :
76867686 fixed = fixup_partial_type (var .type )
@@ -7707,9 +7707,7 @@ def handle_partial_var_type(
77077707 if in_scope :
77087708 context = partial_types [node ]
77097709 if is_local or not self .options .allow_untyped_globals :
7710- self .msg .need_annotation_for_var (
7711- node , context , self .options .python_version
7712- )
7710+ self .msg .need_annotation_for_var (node , context , self .options )
77137711 self .partial_reported .add (node )
77147712 else :
77157713 # Defer the node -- we might get a better type in the outer scope
0 commit comments