MCPcopy
hub / github.com/python/mypy / _prepare_class_namespace

Function _prepare_class_namespace

mypy/plugins/common.py:305–321  ·  view source on GitHub ↗
(cls: ClassDef, name: str)

Source from the content-addressed store, hash-verified

303
304
305def _prepare_class_namespace(cls: ClassDef, name: str) -> None:
306 info = cls.info
307 assert info
308
309 # First remove any previously generated methods with the same name
310 # to avoid clashes and problems in the semantic analyzer.
311 if name in info.names:
312 sym = info.names[name]
313 if sym.plugin_generated and isinstance(sym.node, FuncDef):
314 cls.defs.body.remove(sym.node)
315
316 # NOTE: we would like the plugin generated node to dominate, but we still
317 # need to keep any existing definitions so they get semantically analyzed.
318 if name in info.names:
319 # Get a nice unique name instead.
320 r_name = get_unique_redefinition_name(name, info.names)
321 info.names[r_name] = info.names[name]
322
323
324def _add_method_by_spec(

Callers 2

add_method_to_classFunction · 0.85

Calls 3

isinstanceFunction · 0.85
removeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…