Skip to content

Commit

Permalink
Fix infinite getattr recursion bug by properly setting _populated in …
Browse files Browse the repository at this point in the history
…getattr.
  • Loading branch information
bboe committed Dec 13, 2011
1 parent b57d148 commit cfd7d76
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Expand Up @@ -213,7 +213,7 @@ max-statements=50
max-parents=9

# Maximum number of attributes for a class (see R0902).
max-attributes=8
max-attributes=10

# Minimum number of public methods for a class (see R0903).
min-public-methods=2
Expand Down
5 changes: 3 additions & 2 deletions reddit/objects.py
Expand Up @@ -51,9 +51,10 @@ def _populate(self, json_dict, fetch):

def __getattr__(self, attr):
if not self._populated:
self._populate(None, True)
self._populated = self._populate(None, True)
return getattr(self, attr)
raise AttributeError
raise AttributeError('\'%s\' has no attribute \'%s\'' % (type(self),
attr))

def __setattr__(self, name, value):
if value and name == 'subreddit':
Expand Down
7 changes: 7 additions & 0 deletions reddit/reddit_test.py
Expand Up @@ -315,6 +315,10 @@ def test_make_moderator(self):
self.subreddit.make_moderator(self.other, r=str(self.subreddit))
self.assertTrue(self.other in self.subreddit.get_moderators())

def test_make_moderator_by_name(self):
self.subreddit.make_moderator(str(self.other), r=str(self.subreddit))
self.assertTrue(self.other in self.subreddit.get_moderators())

def test_remove_contributor(self):
self.subreddit.remove_contributor(self.other)
self.assertFalse(self.other in self.subreddit.get_contributors())
Expand Down Expand Up @@ -479,6 +483,9 @@ def setUp(self):
self.configure()
self.subreddit = self.r.get_subreddit(self.sr)

def test_attribute_error(self):
self.assertRaises(AttributeError, getattr, self.subreddit, 'foo')

def test_get_my_moderation(self):
for subreddit in self.r.user.my_moderation():
if subreddit.display_name == self.sr:
Expand Down

0 comments on commit cfd7d76

Please sign in to comment.