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]
)
| 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>" |
no test coverage detected