Skip to content

Commit df6418d

Browse files
committed
fix extended raise error message
1 parent 9bb029f commit df6418d

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

mypy/checker.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5100,22 +5100,15 @@ def type_check_raise(self, e: Expression, s: RaiseStmt, optional: bool = False)
51005100
# where we allow `raise e from None`.
51015101
expected_type_items.append(NoneType())
51025102

5103-
self.check_subtype(
5104-
typ, UnionType.make_union(expected_type_items), s, message_registry.INVALID_EXCEPTION
5105-
)
5103+
message = message_registry.INVALID_EXCEPTION
5104+
if isinstance(typ, Instance) and typ.type.fullname == "builtins._NotImplementedType":
5105+
message = message.with_additional_msg('; did you mean "NotImplementedError"?')
5106+
self.check_subtype(typ, UnionType.make_union(expected_type_items), s, message)
51065107

51075108
if isinstance(typ, FunctionLike):
51085109
# https://github.com/python/mypy/issues/11089
51095110
self.expr_checker.check_call(typ, [], [], e)
51105111

5111-
if isinstance(typ, Instance) and typ.type.fullname == "builtins._NotImplementedType":
5112-
self.fail(
5113-
message_registry.INVALID_EXCEPTION.with_additional_msg(
5114-
'; did you mean "NotImplementedError"?'
5115-
),
5116-
s,
5117-
)
5118-
51195112
def visit_try_stmt(self, s: TryStmt) -> None:
51205113
"""Type check a try statement."""
51215114

0 commit comments

Comments
 (0)