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

Method lookup_operator

mypy/checkexpr.py:4075–4095  ·  view source on GitHub ↗

Looks up the given operator and returns the corresponding type, if it exists.

(self, op_name: str, base_type: Type, context: Context)

Source from the content-addressed store, hash-verified

4073 )
4074
4075 def lookup_operator(self, op_name: str, base_type: Type, context: Context) -> Type | None:
4076 """Looks up the given operator and returns the corresponding type,
4077 if it exists."""
4078
4079 # This check is an important performance optimization.
4080 if not has_operator(base_type, op_name):
4081 return None
4082
4083 with self.msg.filter_errors() as w:
4084 member = analyze_member_access(
4085 name=op_name,
4086 typ=base_type,
4087 is_lvalue=False,
4088 is_super=False,
4089 is_operator=True,
4090 original_type=base_type,
4091 context=context,
4092 chk=self.chk,
4093 in_literal_context=self.is_literal_context(),
4094 )
4095 return None if w.has_new_errors() else member
4096
4097 def lookup_definer(self, typ: Instance, attr_name: str) -> str | None:
4098 """Returns the name of the class that contains the actual definition of attr_name.

Callers 1

check_op_reversibleMethod · 0.95

Calls 5

is_literal_contextMethod · 0.95
has_operatorFunction · 0.90
analyze_member_accessFunction · 0.90
filter_errorsMethod · 0.80
has_new_errorsMethod · 0.80

Tested by

no test coverage detected