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

Method method_fullname

mypy/checkexpr.py:682–708  ·  view source on GitHub ↗

Convert a method name to a fully qualified name, based on the type of the object that it is invoked on. Return `None` if the name of `object_type` cannot be determined.

(self, object_type: Type, method_name: str)

Source from the content-addressed store, hash-verified

680 self.strfrm_checker.check_str_format_call(e, format_value)
681
682 def method_fullname(self, object_type: Type, method_name: str) -> str | None:
683 """Convert a method name to a fully qualified name, based on the type of the object that
684 it is invoked on. Return `None` if the name of `object_type` cannot be determined.
685 """
686 object_type = get_proper_type(object_type)
687
688 if isinstance(object_type, CallableType) and object_type.is_type_obj():
689 # For class method calls, object_type is a callable representing the class object.
690 # We "unwrap" it to a regular type, as the class/instance method difference doesn't
691 # affect the fully qualified name.
692 object_type = get_proper_type(object_type.ret_type)
693 elif isinstance(object_type, TypeType):
694 object_type = object_type.item
695
696 type_name = None
697 if isinstance(object_type, Instance):
698 type_name = object_type.type.fullname
699 elif isinstance(object_type, (TypedDictType, LiteralType)):
700 info = object_type.fallback.type.get_containing_type_info(method_name)
701 type_name = info.fullname if info is not None else None
702 elif isinstance(object_type, TupleType):
703 type_name = tuple_fallback(object_type).type.fullname
704
705 if type_name:
706 return f"{type_name}.{method_name}"
707 else:
708 return None
709
710 def always_returns_none(self, node: Expression) -> bool:
711 """Check if `node` refers to something explicitly annotated as only returning None."""

Callers 7

visit_call_expr_innerMethod · 0.95
check_union_call_exprMethod · 0.95
check_method_callMethod · 0.95
visit_decorator_innerMethod · 0.45

Calls 5

get_proper_typeFunction · 0.90
tuple_fallbackFunction · 0.90
isinstanceFunction · 0.85
is_type_objMethod · 0.45

Tested by

no test coverage detected