Skip to content

Commit 6d940a6

Browse files
committed
AttributeError thrown for from_dict and small fixes
1 parent 3e2fc09 commit 6d940a6

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

setup.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
from setuptools import find_packages, setup
22

3-
with open('README.md') as f:
3+
with open('README.md', encoding='utf-8') as f:
44
long_description = f.read()
55

66
setup(
77
name='typed-argument-parser',
8-
version='1.4.1',
8+
version='1.4.2',
99
author='Jesse Michel and Kyle Swanson',
10-
author_email='[email protected]',
10+
1111
description='Typed Argument Parser',
1212
long_description=long_description,
1313
long_description_content_type='text/markdown',
1414
url='https://github.com/swansonk14/typed-argument-parser',
15-
download_url='https://github.com/swansonk14/typed-argument-parser/v_1.4.1.tar.gz',
15+
download_url='https://github.com/swansonk14/typed-argument-parser/v_1.4.2.tar.gz',
1616
license='MIT',
1717
packages=find_packages(),
18-
package_data={"tap": ["py.typed"]},
18+
package_data={'tap': ['py.typed']},
1919
install_requires=[
2020
'typing_extensions >= 3.7.4',
21-
'typing-inspect >= 0.5',
21+
'typing-inspect >= 0.5'
2222
],
2323
tests_require=['pytest'],
2424
classifiers=[
@@ -28,7 +28,7 @@
2828
'Programming Language :: Python :: 3.8',
2929
'License :: OSI Approved :: MIT License',
3030
'Operating System :: OS Independent',
31-
"Typing :: Typed",
31+
"Typing :: Typed"
3232
],
3333
keywords=[
3434
'typing',

tap/tap.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,8 @@ def from_dict(self, args_dict: Dict[str, Any], skip_unsettable: bool = False) ->
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.
415+
:param skip_unsettable: When True, skips attributes that cannot be set in the Tap object,
416+
e.g. properties without setters.
415417
"""
416418
# All of the required arguments must be provided or already set
417419
required_args = {a.dest for a in self._actions if a.required}
@@ -428,9 +430,9 @@ def from_dict(self, args_dict: Dict[str, Any], skip_unsettable: bool = False) ->
428430
setattr(self, key, value)
429431
except AttributeError:
430432
if not skip_unsettable:
431-
raise AttributeError(f'Cannot set attribute "{key}" to "{value}." '
433+
raise AttributeError(f'Cannot set attribute "{key}" to "{value}". '
432434
f'To skip arguments that cannot be set \n'
433-
f'"skip_unsettable = True" \n')
435+
f'\t"skip_unsettable = True"')
434436

435437
self._parsed = True
436438

tap/utils.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,9 @@ def fix_py36_copy(func: Callable) -> Callable:
340340
341341
Based on https://stackoverflow.com/questions/6279305/typeerror-cannot-deepcopy-this-pattern-object
342342
"""
343-
if sys.version_info[:2] != (3, 6):
343+
if sys.version_info[:2] > (3, 6):
344344
return func
345345

346-
347346
@wraps(func)
348347
def wrapper(*args, **kwargs):
349348
re_type = type(re.compile(''))
@@ -355,6 +354,8 @@ def wrapper(*args, **kwargs):
355354

356355
if has_prev_val:
357356
copy._deepcopy_dispatch[re_type] = prev_val
357+
else:
358+
del copy._deepcopy_dispatch[re_type]
358359

359360
return result
360361

0 commit comments

Comments
 (0)