Skip to content

Commit a46afa7

Browse files
committed
Fix test after syncing NotImplemented fixture definition with typeshed
Test case testReturnAnyForNotImplementedInNormalMethods become silently invalid after typeshed changes it defintiion of NotImplemented from Any to a subclass to Any. We can store the old behavior by special casing NotImplemented in check_return_stmt.
1 parent 7c4a67e commit a46afa7

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

mypy/checker.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4581,6 +4581,13 @@ def check_return_stmt(self, s: ReturnStmt) -> None:
45814581
s.expr, return_type, allow_none_return=allow_none_func_call
45824582
)
45834583
)
4584+
# Treat NotImplemented as having type Any, consistent with its
4585+
# definition in typeshed prior to python/typeshed#4222.
4586+
if (
4587+
isinstance(typ, Instance)
4588+
and typ.type.fullname == "builtins._NotImplementedType"
4589+
):
4590+
typ = AnyType(TypeOfAny.special_form)
45844591

45854592
if defn.is_async_generator:
45864593
self.fail(message_registry.RETURN_IN_ASYNC_GENERATOR, s)

0 commit comments

Comments
 (0)