Skip to content

Commit

Permalink
Fixing bug in as_dict for subclass Taps
Browse files Browse the repository at this point in the history
  • Loading branch information
swansonk14 committed Jul 16, 2020
1 parent 95fc833 commit 954cc83
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tap/_version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__all__ = ['__version__']

# major, minor, patch
version_info = 1, 5, 1
version_info = 1, 5, 2

# Nice string for the version
__version__ = '.'.join(map(str, version_info))
5 changes: 4 additions & 1 deletion tap/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,10 @@ def as_dict(self) -> Dict[str, Any]:
raise ValueError('You should call `parse_args` before retrieving arguments.')

self_dict = self.__dict__
class_dict = {key: val for key, val in type(self).__dict__.items() if key not in self_dict}
class_dict = self._get_from_self_and_super(
extract_func=lambda super_class: dict(getattr(super_class, '__dict__', dict()))
)
class_dict = {key: val for key, val in class_dict.items() if key not in self_dict}
stored_dict = {**self_dict, **class_dict}

stored_dict = {
Expand Down
17 changes: 17 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,23 @@ def pi(self):
as_dict_res = {'a': 'hi', 'b': 1, 'pi': 3.14}
self.assertEqual(args.as_dict(), as_dict_res)

def test_as_dict_superclass_property(self):
class SuperPropertyTap(Tap):
a: str

@property
def pi(self):
return 3.14

class SubPropertyTap(SuperPropertyTap):
b: int = 1

args = SubPropertyTap()
args = args.parse_args(['--a', 'hi'])

as_dict_res = {'a': 'hi', 'b': 1, 'pi': 3.14}
self.assertEqual(args.as_dict(), as_dict_res)


class TestFromDict(TestCase):

Expand Down

0 comments on commit 954cc83

Please sign in to comment.