Skip to content

Commit

Permalink
Merge pull request #124 from neilvyas/neilvyas/informative-attribute-…
Browse files Browse the repository at this point in the history
…error

Using the class name to make AttributeError on __getattr__ more informative for PRecords.
  • Loading branch information
tobgu committed Feb 9, 2018
2 parents 9e9bc27 + 815129d commit 66caaf1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pyrsistent/_pmap.py
Expand Up @@ -91,7 +91,9 @@ def __getattr__(self, key):
try:
return self[key]
except KeyError:
raise AttributeError("PMap has no attribute '{0}'".format(key))
raise AttributeError(
"{0} has no attribute '{1}'".format(type(self).__name__, key)
)

def iterkeys(self):
for k, _ in self.iteritems():
Expand Down
5 changes: 4 additions & 1 deletion tests/map_test.py
Expand Up @@ -463,7 +463,10 @@ def test_dot_access_of_non_existing_element_raises_attribute_error():
with pytest.raises(AttributeError) as error:
m1.b

assert "'b'" in str(error.value)
error_message = str(error.value)

assert "'b'" in error_message
assert type(m1).__name__ in error_message


def test_pmap_unorderable():
Expand Down

0 comments on commit 66caaf1

Please sign in to comment.