8
8
from pprint import pformat
9
9
from shlex import quote , split
10
10
from types import MethodType
11
- from typing import Any , Callable , Dict , List , Optional , Sequence , Set , Tuple , TypeVar , Union , get_type_hints
11
+ from typing import Any , Callable , List , Optional , Sequence , Set , Tuple , TypeVar , Union , get_type_hints
12
12
from typing_inspect import is_literal_type
13
13
14
14
from tap .utils import (
@@ -53,9 +53,9 @@ def __init__(
53
53
* args ,
54
54
underscores_to_dashes : bool = False ,
55
55
explicit_bool : bool = False ,
56
- config_files : Optional [List [PathLike ]] = None ,
56
+ config_files : Optional [list [PathLike ]] = None ,
57
57
** kwargs ,
58
- ):
58
+ ) -> None :
59
59
"""Initializes the Tap instance.
60
60
61
61
:param args: Arguments passed to the super class ArgumentParser.
@@ -88,7 +88,7 @@ def __init__(
88
88
self .argument_buffer = {}
89
89
90
90
# Create a place to put the subparsers
91
- self ._subparser_buffer : List [ Tuple [str , type , Dict [str , Any ]]] = []
91
+ self ._subparser_buffer : list [ tuple [str , type , dict [str , Any ]]] = []
92
92
93
93
# Get class variables help strings from the comments
94
94
self .class_variables = self ._get_class_variables ()
@@ -369,7 +369,7 @@ def configure(self) -> None:
369
369
pass
370
370
371
371
@staticmethod
372
- def get_reproducibility_info (repo_path : Optional [PathLike ] = None ) -> Dict [str , str ]:
372
+ def get_reproducibility_info (repo_path : Optional [PathLike ] = None ) -> dict [str , str ]:
373
373
"""Gets a dictionary of reproducibility information.
374
374
375
375
Reproducibility information always includes:
@@ -405,7 +405,7 @@ def get_reproducibility_info(repo_path: Optional[PathLike] = None) -> Dict[str,
405
405
406
406
return reproducibility
407
407
408
- def _log_all (self , repo_path : Optional [PathLike ] = None ) -> Dict [str , Any ]:
408
+ def _log_all (self , repo_path : Optional [PathLike ] = None ) -> dict [str , Any ]:
409
409
"""Gets all arguments along with reproducibility information.
410
410
411
411
:param repo_path: Path to the git repo to examine for reproducibility info.
@@ -418,7 +418,10 @@ def _log_all(self, repo_path: Optional[PathLike] = None) -> Dict[str, Any]:
418
418
return arg_log
419
419
420
420
def parse_args (
421
- self : TapType , args : Optional [Sequence [str ]] = None , known_only : bool = False , legacy_config_parsing = False
421
+ self : TapType ,
422
+ args : Optional [Sequence [str ]] = None ,
423
+ known_only : bool = False ,
424
+ legacy_config_parsing : bool = False ,
422
425
) -> TapType :
423
426
"""Parses arguments, sets attributes of self equal to the parsed arguments, and processes arguments.
424
427
@@ -483,7 +486,7 @@ def parse_args(
483
486
return self
484
487
485
488
@classmethod
486
- def _get_from_self_and_super (cls , extract_func : Callable [[type ], dict ]) -> Union [Dict [str , Any ], Dict ]:
489
+ def _get_from_self_and_super (cls , extract_func : Callable [[type ], dict ]) -> Union [dict [str , Any ], dict ]:
487
490
"""Returns a dictionary mapping variable names to values.
488
491
489
492
Variables and values are extracted from classes using key starting
@@ -518,7 +521,7 @@ def _get_from_self_and_super(cls, extract_func: Callable[[type], dict]) -> Union
518
521
519
522
return dictionary
520
523
521
- def _get_class_dict (self ) -> Dict [str , Any ]:
524
+ def _get_class_dict (self ) -> dict [str , Any ]:
522
525
"""Returns a dictionary mapping class variable names to values from the class dict."""
523
526
class_dict = self ._get_from_self_and_super (
524
527
extract_func = lambda super_class : dict (getattr (super_class , "__dict__" , dict ()))
@@ -531,7 +534,7 @@ def _get_class_dict(self) -> Dict[str, Any]:
531
534
532
535
return class_dict
533
536
534
- def _get_annotations (self ) -> Dict [str , Any ]:
537
+ def _get_annotations (self ) -> dict [str , Any ]:
535
538
"""Returns a dictionary mapping variable names to their type annotations."""
536
539
return self ._get_from_self_and_super (extract_func = lambda super_class : dict (get_type_hints (super_class )))
537
540
@@ -559,15 +562,15 @@ def _get_class_variables(self) -> dict:
559
562
560
563
return class_variables
561
564
562
- def _get_argument_names (self ) -> Set [str ]:
565
+ def _get_argument_names (self ) -> set [str ]:
563
566
"""Returns a list of variable names corresponding to the arguments."""
564
567
return (
565
568
{get_dest (* name_or_flags , ** kwargs ) for name_or_flags , kwargs in self .argument_buffer .values ()}
566
569
| set (self ._get_class_dict ().keys ())
567
570
| set (self ._annotations .keys ())
568
571
) - {"help" }
569
572
570
- def as_dict (self ) -> Dict [str , Any ]:
573
+ def as_dict (self ) -> dict [str , Any ]:
571
574
"""Returns the member variables corresponding to the parsed arguments.
572
575
573
576
Note: This does not include attributes set directly on an instance
@@ -596,7 +599,7 @@ def as_dict(self) -> Dict[str, Any]:
596
599
597
600
return stored_dict
598
601
599
- def from_dict (self , args_dict : Dict [str , Any ], skip_unsettable : bool = False ) -> TapType :
602
+ def from_dict (self , args_dict : dict [str , Any ], skip_unsettable : bool = False ) -> TapType :
600
603
"""Loads arguments from a dictionary, ensuring all required arguments are set.
601
604
602
605
:param args_dict: A dictionary from argument names to the values of the arguments.
@@ -682,7 +685,7 @@ def load(
682
685
683
686
return self
684
687
685
- def _load_from_config_files (self , config_files : Optional [List [str ]]) -> List [str ]:
688
+ def _load_from_config_files (self , config_files : Optional [list [str ]]) -> list [str ]:
686
689
"""Loads arguments from a list of configuration files containing command line arguments.
687
690
688
691
:param config_files: A list of paths to configuration files containing the command line arguments
@@ -708,7 +711,7 @@ def __str__(self) -> str:
708
711
"""
709
712
return pformat (self .as_dict ())
710
713
711
- def __deepcopy__ (self , memo : Dict [int , Any ] = None ) -> TapType :
714
+ def __deepcopy__ (self , memo : dict [int , Any ] = None ) -> TapType :
712
715
"""Deepcopy the Tap object."""
713
716
copied = type (self ).__new__ (type (self ))
714
717
@@ -722,11 +725,11 @@ def __deepcopy__(self, memo: Dict[int, Any] = None) -> TapType:
722
725
723
726
return copied
724
727
725
- def __getstate__ (self ) -> Dict [str , Any ]:
728
+ def __getstate__ (self ) -> dict [str , Any ]:
726
729
"""Gets the state of the object for pickling."""
727
730
return self .as_dict ()
728
731
729
- def __setstate__ (self , d : Dict [str , Any ]) -> None :
732
+ def __setstate__ (self , d : dict [str , Any ]) -> None :
730
733
"""
731
734
Initializes the object with the provided dictionary of arguments for unpickling.
732
735
0 commit comments