Skip to content

Commit

Permalink
Merge pull request #118 from vreuter/safe_copy
Browse files Browse the repository at this point in the history
Respect protected members
  • Loading branch information
vreuter committed Jan 30, 2019
2 parents ed0e9bb + 1641a5d commit 5b5523c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changelog
******************************
- **v0.9.2** (*2019-01-30*):

- Never echo protected-looking attribute request.

- **v0.9.1** (*2019-01-29*):

- Fixed a bug in NGSTk that caused errors for read counting functions on
Expand Down
3 changes: 2 additions & 1 deletion pypiper/AttributeDict.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def __getattr__(self, name):
if name in self.__dict__.keys():
return self.name
else:
if self.return_defaults:
if self.return_defaults and not \
(name.startswith("__") and name.endswith("__")):
# If this object has default mode on, then we should
# simply return the name of the requested attribute as
# a default, if no attribute with that name exists.
Expand Down
2 changes: 1 addition & 1 deletion pypiper/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.9.1"
__version__ = "0.9.2"
16 changes: 16 additions & 0 deletions tests/test_attribute_dict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
""" Tests for pypiper implementation of AttributeDict """

import pytest
from pypiper import AttributeDict as AD


@pytest.mark.parametrize("base", ["random", "irrelevant", "arbitrary"])
@pytest.mark.parametrize("protect", [False, True])
def test_echo_respects_protected(base, protect):
""" Regardless of AttributeDict behavior, protected member isn't echoed. """
ad = AD({}, default=True)
if protect:
with pytest.raises(AttributeError):
ad.__getattr__("__{}__".format(base))
else:
assert base == ad.__getattr__(base)

0 comments on commit 5b5523c

Please sign in to comment.