Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Avoid triggering fetch for all hidden attributes
  • Loading branch information
bboe committed Nov 27, 2016
1 parent 9ac8bc6 commit 280525c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGES.rst
@@ -1,6 +1,14 @@
Change Log
==========

Unreleased
----------

**Fixed**

* Fix bug where ipython tries to access attribute
``_ipython_canary_method_should_not_exist_`` resulting in a useless fetch.

4.0.0rc3 (2016/11/26)
---------------------

Expand Down
2 changes: 1 addition & 1 deletion praw/models/reddit/base.py
Expand Up @@ -27,7 +27,7 @@ def __eq__(self, other):

def __getattr__(self, attribute):
"""Return the value of `attrribute`."""
if not attribute.startswith('__') and not self._fetched:
if not attribute.startswith('_') and not self._fetched:
self._fetch()
return getattr(self, attribute)
raise AttributeError('{!r} object has no attribute {!r}'
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/models/reddit/test_comment.py
Expand Up @@ -54,3 +54,9 @@ def test_repr(self):
def test_str(self):
comment = Comment(self.reddit, _data={'id': 'dummy'})
assert str(comment) == 'dummy'

def test_unset_hidden_attribute_does_not_fetch(self):
comment = Comment(self.reddit, _data={'id': 'dummy'})
with pytest.raises(AttributeError):
comment._ipython_canary_method_should_not_exist_
assert not comment._fetched

0 comments on commit 280525c

Please sign in to comment.