@@ -483,9 +483,7 @@ def parse_args(
483
483
return self
484
484
485
485
@classmethod
486
- def _get_from_self_and_super (
487
- cls , extract_func : Callable [[type ], dict ], * , need_tap_cls : bool = True ,
488
- ) -> Union [Dict [str , Any ], Dict ]:
486
+ def _get_from_self_and_super ( cls , extract_func : Callable [[type ], dict ]) -> Union [Dict [str , Any ], Dict ]:
489
487
"""Returns a dictionary mapping variable names to values.
490
488
491
489
Variables and values are extracted from classes using key starting
@@ -496,7 +494,6 @@ def _get_from_self_and_super(
496
494
Super classes are traversed through breadth first search.
497
495
498
496
:param extract_func: A function that extracts from a class a dictionary mapping variables to values.
499
- :param need_tap_cls: If False, variables from the Tap and ArgumentParser classes are ignored.
500
497
:return: A dictionary mapping variable names to values from the class dict.
501
498
"""
502
499
visited = set ()
@@ -506,10 +503,7 @@ def _get_from_self_and_super(
506
503
while len (super_classes ) > 0 :
507
504
super_class = super_classes .pop (0 )
508
505
509
- if not need_tap_cls and super_class is Tap :
510
- break
511
-
512
- if super_class not in visited and issubclass (super_class , Tap ):
506
+ if super_class not in visited and issubclass (super_class , Tap ) and super_class is not Tap :
513
507
super_dictionary = extract_func (super_class )
514
508
515
509
# Update only unseen variables to avoid overriding subclass values
@@ -527,8 +521,7 @@ def _get_from_self_and_super(
527
521
def _get_class_dict (self ) -> Dict [str , Any ]:
528
522
"""Returns a dictionary mapping class variable names to values from the class dict."""
529
523
class_dict = self ._get_from_self_and_super (
530
- extract_func = lambda super_class : dict (getattr (super_class , "__dict__" , dict ())),
531
- need_tap_cls = False ,
524
+ extract_func = lambda super_class : dict (getattr (super_class , "__dict__" , dict ()))
532
525
)
533
526
class_dict = {
534
527
var : val
@@ -545,18 +538,15 @@ def _get_class_dict(self) -> Dict[str, Any]:
545
538
def _get_annotations (self ) -> Dict [str , Any ]:
546
539
"""Returns a dictionary mapping variable names to their type annotations."""
547
540
return self ._get_from_self_and_super (
548
- extract_func = lambda super_class : dict (get_type_hints (super_class )),
549
- need_tap_cls = False ,
541
+ extract_func = lambda super_class : dict (get_type_hints (super_class ))
550
542
)
551
543
552
544
def _get_class_variables (self ) -> dict :
553
545
"""Returns a dictionary mapping class variables names to their additional information."""
554
546
class_variable_names = {** self ._get_annotations (), ** self ._get_class_dict ()}.keys ()
555
547
556
548
try :
557
- class_variables = self ._get_from_self_and_super (
558
- extract_func = get_class_variables , need_tap_cls = False ,
559
- )
549
+ class_variables = self ._get_from_self_and_super (extract_func = get_class_variables )
560
550
561
551
# Handle edge-case of source code modification while code is running
562
552
variables_to_add = class_variable_names - class_variables .keys ()
@@ -597,7 +587,6 @@ def as_dict(self) -> Dict[str, Any]:
597
587
self_dict = self .__dict__
598
588
class_dict = self ._get_from_self_and_super (
599
589
extract_func = lambda super_class : dict (getattr (super_class , "__dict__" , dict ())),
600
- need_tap_cls = False ,
601
590
)
602
591
class_dict = {key : val for key , val in class_dict .items () if key not in self_dict }
603
592
stored_dict = {** self_dict , ** class_dict }
0 commit comments