diff --git a/tap/tap.py b/tap/tap.py index 4d76355..694ed94 100644 --- a/tap/tap.py +++ b/tap/tap.py @@ -408,7 +408,7 @@ def as_dict(self) -> Dict[str, Any]: return {var: getattr(self, var) for var in self._get_argument_names()} - def from_dict(self, args_dict: Dict[str, Any]) -> None: + def from_dict(self, args_dict: Dict[str, Any], skip_unsettable: bool = False) -> None: """Loads arguments from a dictionary, ensuring all required arguments are set. :param args_dict: A dictionary from argument names to the values of the arguments. @@ -426,8 +426,11 @@ def from_dict(self, args_dict: Dict[str, Any]) -> None: for key, value in args_dict.items(): try: setattr(self, key, value) - except AttributeError as e: - warnings.warn(e) + except AttributeError: + if not skip_unsettable: + raise AttributeError(f'Cannot set attribute "{key}" to "{value}." ' + f'To skip arguments that cannot be set \n' + f'"skip_unsettable = True" \n') self._parsed = True diff --git a/tap/utils.py b/tap/utils.py index 4f75a5c..2158f1b 100644 --- a/tap/utils.py +++ b/tap/utils.py @@ -343,10 +343,10 @@ def fix_py36_copy(func: Callable) -> Callable: if sys.version_info[:2] != (3, 6): return func - re_type = type(re.compile('')) @wraps(func) def wrapper(*args, **kwargs): + re_type = type(re.compile('')) has_prev_val = re_type in copy._deepcopy_dispatch prev_val = copy._deepcopy_dispatch.get(re_type, None) copy._deepcopy_dispatch[type(re.compile(''))] = lambda r, _: r @@ -355,8 +355,6 @@ def wrapper(*args, **kwargs): if has_prev_val: copy._deepcopy_dispatch[re_type] = prev_val - else: - del copy._deepcopy_dispatch[re_type] return result diff --git a/tests/test_integration.py b/tests/test_integration.py index f16bf7a..cc95121 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -900,6 +900,7 @@ class SimpleFromDictTap(Tap): class TestStoringTap(TestCase): + def test_save_load_simple(self): class SimpleSaveLoadTap(Tap): a: str