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

Function _analyze_class

mypy/plugins/functools.py:113–134  ·  view source on GitHub ↗

Analyze the class body, its parents, and return the comparison methods found.

(ctx: mypy.plugin.ClassDefContext)

Source from the content-addressed store, hash-verified

111
112
113def _analyze_class(ctx: mypy.plugin.ClassDefContext) -> dict[str, _MethodInfo | None]:
114 """Analyze the class body, its parents, and return the comparison methods found."""
115 # Traverse the MRO and collect ordering methods.
116 comparison_methods: dict[str, _MethodInfo | None] = {}
117 # Skip object because total_ordering does not use methods from object
118 for cls in ctx.cls.info.mro[:-1]:
119 for name in _ORDERING_METHODS:
120 if name in cls.names and name not in comparison_methods:
121 node = cls.names[name].node
122 if isinstance(node, SYMBOL_FUNCBASE_TYPES) and isinstance(node.type, CallableType):
123 comparison_methods[name] = _MethodInfo(node.is_static, node.type)
124 continue
125
126 if isinstance(node, Var):
127 proper_type = get_proper_type(node.type)
128 if isinstance(proper_type, CallableType):
129 comparison_methods[name] = _MethodInfo(node.is_staticmethod, proper_type)
130 continue
131
132 comparison_methods[name] = None
133
134 return comparison_methods
135
136
137def partial_new_callback(ctx: mypy.plugin.FunctionContext) -> Type:

Calls 3

get_proper_typeFunction · 0.90
isinstanceFunction · 0.85
_MethodInfoClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…