diff --git a/mypy/messages.py b/mypy/messages.py index 49c39fa9405b..cc9728f99e1d 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -1341,15 +1341,16 @@ def cannot_instantiate_abstract_class( return if len(attrs_with_none) == 1: note = ( - "The following method was marked implicitly abstract because it has an empty " - "function body: {}. If it is not meant to be abstract, explicitly return None." + f"{attrs_with_none[0]} is implicitly abstract because it has an empty function " + "body. If it is not meant to be abstract, explicitly `return` or `return None`." ) else: note = ( "The following methods were marked implicitly abstract because they have empty " - "function bodies: {}. If they are not meant to be abstract, explicitly return None." + f"function bodies: {format_string_list(attrs_with_none)}. " + "If they are not meant to be abstract, explicitly `return` or `return None`." ) - self.note(note.format(format_string_list(attrs_with_none)), context, code=codes.ABSTRACT) + self.note(note, context, code=codes.ABSTRACT) def base_class_definitions_incompatible( self, name: str, base1: TypeInfo, base2: TypeInfo, context: Context diff --git a/test-data/unit/check-protocols.test b/test-data/unit/check-protocols.test index 3302fd4402b3..8cdfd2a3e0d9 100644 --- a/test-data/unit/check-protocols.test +++ b/test-data/unit/check-protocols.test @@ -3105,14 +3105,14 @@ class NoneCompatible(Protocol): class A(NoneCompatible): ... A() # E: Cannot instantiate abstract class "A" with abstract attributes "f", "g", "h", "i" and "j" \ - # N: The following methods were marked implicitly abstract because they have empty function bodies: "f", "g", "h", "i" and "j". If they are not meant to be abstract, explicitly return None. + # N: The following methods were marked implicitly abstract because they have empty function bodies: "f", "g", "h", "i" and "j". If they are not meant to be abstract, explicitly `return` or `return None`. class NoneCompatible2(Protocol): def f(self, x: int): ... class B(NoneCompatible2): ... B() # E: Cannot instantiate abstract class "B" with abstract attribute "f" \ - # N: The following method was marked implicitly abstract because it has an empty function body: "f". If it is not meant to be abstract, explicitly return None. + # N: "f" is implicitly abstract because it has an empty function body. If it is not meant to be abstract, explicitly `return` or `return None`. class NoneCompatible3(Protocol): @abstractmethod