Skip to content

Commit 3e2fc09

Browse files
author
Jesse Michel
committed
Updated attribute error and modified fix_py_36
1 parent 5f718c4 commit 3e2fc09

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

tap/tap.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def as_dict(self) -> Dict[str, Any]:
408408

409409
return {var: getattr(self, var) for var in self._get_argument_names()}
410410

411-
def from_dict(self, args_dict: Dict[str, Any]) -> None:
411+
def from_dict(self, args_dict: Dict[str, Any], skip_unsettable: bool = False) -> None:
412412
"""Loads arguments from a dictionary, ensuring all required arguments are set.
413413
414414
: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:
426426
for key, value in args_dict.items():
427427
try:
428428
setattr(self, key, value)
429-
except AttributeError as e:
430-
warnings.warn(e)
429+
except AttributeError:
430+
if not skip_unsettable:
431+
raise AttributeError(f'Cannot set attribute "{key}" to "{value}." '
432+
f'To skip arguments that cannot be set \n'
433+
f'"skip_unsettable = True" \n')
431434

432435
self._parsed = True
433436

tap/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,10 @@ def fix_py36_copy(func: Callable) -> Callable:
343343
if sys.version_info[:2] != (3, 6):
344344
return func
345345

346-
re_type = type(re.compile(''))
347346

348347
@wraps(func)
349348
def wrapper(*args, **kwargs):
349+
re_type = type(re.compile(''))
350350
has_prev_val = re_type in copy._deepcopy_dispatch
351351
prev_val = copy._deepcopy_dispatch.get(re_type, None)
352352
copy._deepcopy_dispatch[type(re.compile(''))] = lambda r, _: r
@@ -355,8 +355,6 @@ def wrapper(*args, **kwargs):
355355

356356
if has_prev_val:
357357
copy._deepcopy_dispatch[re_type] = prev_val
358-
else:
359-
del copy._deepcopy_dispatch[re_type]
360358

361359
return result
362360

tests/test_integration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,7 @@ class SimpleFromDictTap(Tap):
900900

901901

902902
class TestStoringTap(TestCase):
903+
903904
def test_save_load_simple(self):
904905
class SimpleSaveLoadTap(Tap):
905906
a: str

0 commit comments

Comments
 (0)