@@ -2554,7 +2554,7 @@ def parse(self, input: str) -> str:
2554
2554
return printer .f .getvalue ()
2555
2555
2556
2556
def _module_and_class (
2557
- self , fields : Iterable [str ]
2557
+ self , fields : Sequence [str ]
2558
2558
) -> tuple [Module | Clinic , Class | None ]:
2559
2559
"""
2560
2560
fields should be an iterable of field names.
@@ -2563,26 +2563,20 @@ def _module_and_class(
2563
2563
this function is only ever used to find the parent of where
2564
2564
a new class/module should go.
2565
2565
"""
2566
- parent : Clinic | Module | Class
2567
- child : Module | Class | None
2568
- module : Clinic | Module
2566
+ parent : Clinic | Module | Class = self
2567
+ module : Clinic | Module = self
2569
2568
cls : Class | None = None
2570
- so_far : list [str ] = []
2571
2569
2572
- parent = module = self
2573
-
2574
- for field in fields :
2575
- so_far .append (field )
2570
+ for idx , field in enumerate (fields ):
2576
2571
if not isinstance (parent , Class ):
2577
- child = parent .modules .get (field )
2578
- if child :
2579
- parent = module = child
2572
+ if field in parent .modules :
2573
+ parent = module = parent .modules [field ]
2580
2574
continue
2581
- child = parent .classes .get (field )
2582
- if not child :
2583
- fullname = "." .join (so_far )
2575
+ if field in parent .classes :
2576
+ parent = cls = parent .classes [field ]
2577
+ else :
2578
+ fullname = "." .join (fields [idx :])
2584
2579
fail (f"Parent class or module { fullname !r} does not exist." )
2585
- cls = parent = child
2586
2580
2587
2581
return module , cls
2588
2582
0 commit comments