Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Avoid triggering fetch for all hidden attributes
- Loading branch information
Showing
with
15 additions
and
1 deletion.
-
+8
−0
CHANGES.rst
-
+1
−1
praw/models/reddit/base.py
-
+6
−0
tests/unit/models/reddit/test_comment.py
|
|
@@ -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) |
|
|
--------------------- |
|
|
|
|
|
|
@@ -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}' |
|
|
|
@@ -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 |