MCPcopy Create free account
hub / github.com/python/cpython / _module_and_class

Method _module_and_class

Tools/clinic/libclinic/app.py:243–268  ·  view source on GitHub ↗

fields should be an iterable of field names. returns a tuple of (module, class). the module object could actually be self (a clinic object). this function is only ever used to find the parent of where a new class/module should go.

(
        self, fields: Sequence[str]
    )

Source from the content-addressed store, hash-verified

241 return printer.f.getvalue()
242
243 def _module_and_class(
244 self, fields: Sequence[str]
245 ) -> tuple[Module | Clinic, Class | None]:
246 """
247 fields should be an iterable of field names.
248 returns a tuple of (module, class).
249 the module object could actually be self (a clinic object).
250 this function is only ever used to find the parent of where
251 a new class/module should go.
252 """
253 parent: Clinic | Module | Class = self
254 module: Clinic | Module = self
255 cls: Class | None = None
256
257 for idx, field in enumerate(fields):
258 fullname = ".".join(fields[:idx + 1])
259 if not isinstance(parent, Class):
260 if fullname in parent.modules:
261 parent = module = parent.modules[fullname]
262 continue
263 if field in parent.classes:
264 parent = cls = parent.classes[field]
265 else:
266 fail(f"Parent class or module {fullname!r} does not exist.")
267
268 return module, cls
269
270 def __repr__(self) -> str:
271 return "<clinic.Clinic object>"

Callers 5

directive_moduleMethod · 0.80
directive_classMethod · 0.80
parse_cloned_functionMethod · 0.80
state_modulename_nameMethod · 0.80

Calls 3

failFunction · 0.90
enumerateFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected