MCPcopy Index your code
hub / github.com/python/mypy / cannot_instantiate_abstract_class

Method cannot_instantiate_abstract_class

mypy/messages.py:1580–1608  ·  view source on GitHub ↗
(
        self, class_name: str, abstract_attributes: dict[str, bool], context: Context
    )

Source from the content-addressed store, hash-verified

1578 self.pretty_callable_or_overload(new_type, defn, offset=4, parent_error=error)
1579
1580 def cannot_instantiate_abstract_class(
1581 self, class_name: str, abstract_attributes: dict[str, bool], context: Context
1582 ) -> None:
1583 attrs = format_string_list([f'"{a}"' for a in abstract_attributes])
1584 self.fail(
1585 f'Cannot instantiate abstract class "{class_name}" with abstract '
1586 f"attribute{plural_s(abstract_attributes)} {attrs}",
1587 context,
1588 code=codes.ABSTRACT,
1589 )
1590 attrs_with_none = [
1591 f'"{a}"'
1592 for a, implicit_and_can_return_none in abstract_attributes.items()
1593 if implicit_and_can_return_none
1594 ]
1595 if not attrs_with_none:
1596 return
1597 if len(attrs_with_none) == 1:
1598 note = (
1599 f"{attrs_with_none[0]} is implicitly abstract because it has an empty function "
1600 "body. If it is not meant to be abstract, explicitly `return` or `return None`."
1601 )
1602 else:
1603 note = (
1604 "The following methods were marked implicitly abstract because they have empty "
1605 f"function bodies: {format_string_list(attrs_with_none)}. "
1606 "If they are not meant to be abstract, explicitly `return` or `return None`."
1607 )
1608 self.note(note, context, code=codes.ABSTRACT)
1609
1610 def base_class_definitions_incompatible(
1611 self, name: str, base1: TypeInfo, base2: TypeInfo, context: Context

Callers 1

check_callable_callMethod · 0.80

Calls 6

failMethod · 0.95
noteMethod · 0.95
plural_sFunction · 0.90
format_string_listFunction · 0.85
lenFunction · 0.85
itemsMethod · 0.45

Tested by

no test coverage detected