@@ -4942,13 +4942,6 @@ def check_return_stmt(self, s: ReturnStmt) -> None:
49424942 s .expr , return_type , allow_none_return = allow_none_func_call
49434943 )
49444944 )
4945- # Treat NotImplemented as having type Any, consistent with its
4946- # definition in typeshed prior to python/typeshed#4222.
4947- if (
4948- isinstance (typ , Instance )
4949- and typ .type .fullname == "builtins._NotImplementedType"
4950- ):
4951- typ = AnyType (TypeOfAny .special_form )
49524945
49534946 if defn .is_async_generator :
49544947 self .fail (message_registry .RETURN_IN_ASYNC_GENERATOR , s )
@@ -4961,10 +4954,6 @@ def check_return_stmt(self, s: ReturnStmt) -> None:
49614954 self .options .warn_return_any
49624955 and not self .current_node_deferred
49634956 and not is_proper_subtype (AnyType (TypeOfAny .special_form ), return_type )
4964- and not (
4965- defn .name in BINARY_MAGIC_METHODS
4966- and is_literal_not_implemented (s .expr )
4967- )
49684957 and not (
49694958 isinstance (return_type , Instance )
49704959 and return_type .type .fullname == "builtins.object"
@@ -4982,6 +4971,14 @@ def check_return_stmt(self, s: ReturnStmt) -> None:
49824971 if is_lambda or isinstance (typ , NoneType ):
49834972 return
49844973 self .fail (message_registry .NO_RETURN_VALUE_EXPECTED , s )
4974+ elif (
4975+ isinstance (typ , Instance )
4976+ and typ .type .fullname == "builtins._NotImplementedType"
4977+ and (
4978+ (defn .name in BINARY_MAGIC_METHODS or defn .name == "__subclasshook__" )
4979+ )
4980+ ):
4981+ return
49854982 else :
49864983 self .check_subtype (
49874984 subtype_label = "got" ,
0 commit comments