Skip to content

Commit

Permalink
AttributeError thrown for from_dict and small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
swansonk14 committed Apr 13, 2020
1 parent 3e2fc09 commit 6d940a6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
14 changes: 7 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
from setuptools import find_packages, setup

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

setup(
name='typed-argument-parser',
version='1.4.1',
version='1.4.2',
author='Jesse Michel and Kyle Swanson',
author_email='[email protected]',
author_email='[email protected], [email protected]',
description='Typed Argument Parser',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/swansonk14/typed-argument-parser',
download_url='https://github.com/swansonk14/typed-argument-parser/v_1.4.1.tar.gz',
download_url='https://github.com/swansonk14/typed-argument-parser/v_1.4.2.tar.gz',
license='MIT',
packages=find_packages(),
package_data={"tap": ["py.typed"]},
package_data={'tap': ['py.typed']},
install_requires=[
'typing_extensions >= 3.7.4',
'typing-inspect >= 0.5',
'typing-inspect >= 0.5'
],
tests_require=['pytest'],
classifiers=[
Expand All @@ -28,7 +28,7 @@
'Programming Language :: Python :: 3.8',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
"Typing :: Typed",
"Typing :: Typed"
],
keywords=[
'typing',
Expand Down
6 changes: 4 additions & 2 deletions tap/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ def from_dict(self, args_dict: Dict[str, Any], skip_unsettable: bool = False) ->
"""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.
:param skip_unsettable: When True, skips attributes that cannot be set in the Tap object,
e.g. properties without setters.
"""
# All of the required arguments must be provided or already set
required_args = {a.dest for a in self._actions if a.required}
Expand All @@ -428,9 +430,9 @@ def from_dict(self, args_dict: Dict[str, Any], skip_unsettable: bool = False) ->
setattr(self, key, value)
except AttributeError:
if not skip_unsettable:
raise AttributeError(f'Cannot set attribute "{key}" to "{value}." '
raise AttributeError(f'Cannot set attribute "{key}" to "{value}". '
f'To skip arguments that cannot be set \n'
f'"skip_unsettable = True" \n')
f'\t"skip_unsettable = True"')

self._parsed = True

Expand Down
5 changes: 3 additions & 2 deletions tap/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,9 @@ def fix_py36_copy(func: Callable) -> Callable:
Based on https://stackoverflow.com/questions/6279305/typeerror-cannot-deepcopy-this-pattern-object
"""
if sys.version_info[:2] != (3, 6):
if sys.version_info[:2] > (3, 6):
return func


@wraps(func)
def wrapper(*args, **kwargs):
re_type = type(re.compile(''))
Expand All @@ -355,6 +354,8 @@ def wrapper(*args, **kwargs):

if has_prev_val:
copy._deepcopy_dispatch[re_type] = prev_val
else:
del copy._deepcopy_dispatch[re_type]

return result

Expand Down

0 comments on commit 6d940a6

Please sign in to comment.