Repository: praw-dev/praw

Issue:
Accessing emoji causes recusion limit error
Given a `client_id`, `client_secret`, and `user_agent` a simple access of a the lazily loaded properties (`emoji`, `fullname`) on `subreddit` causes a problem.  Code below should recreate that problem easily.

    #!/usr/bin/env python3.6

    def recreate_problem(client_id, client_secret, user_agent):
        import praw

        reddit_name = 'sfwpornnetwork'
        reddit = praw.Reddit(client_id=client_id, client_secret=client_secret, user_agent=user_agent)
        subreddit = reddit.subreddit(reddit_name)
        display(subreddit)


    def display(obj):
        for d in dir(obj):
            try:
                v = getattr(obj, d)
                print(f'        {d}: {v}', flush=True)
                pass
            except Exception as e:
                v = str(e)
                print(f' ERROR: {d}: {v}', flush=True)


    if __name__ == '__main__':
        import sys
        from pathlib import Path

        if len(sys.argv) != 4:
            print(f'Usage: {Path(__file__).stem} <client_id> <client_secret> <user_agent>')
            sys.exit(1)
        client_id = sys.argv[1]
        client_secret = sys.argv[2]
        user_agent = sys.argv[3]
        recreate_problem(client_id, client_secret, user_agent)


Accessing emoji causes recusion limit error
Given a `client_id`, `client_secret`, and `user_agent` a simple access of a the lazily loaded properties (`emoji`, `fullname`) on `subreddit` causes a problem.  Code below should recreate that problem easily.

    #!/usr/bin/env python3.6

    def recreate_problem(client_id, client_secret, user_agent):
        import praw

        reddit_name = 'sfwpornnetwork'
        reddit = praw.Reddit(client_id=client_id, client_secret=client_secret, user_agent=user_agent)
        subreddit = reddit.subreddit(reddit_name)
        display(subreddit)


    def display(obj):
        for d in dir(obj):
            try:
                v = getattr(obj, d)
                print(f'        {d}: {v}', flush=True)
                pass
            except Exception as e:
                v = str(e)
                print(f' ERROR: {d}: {v}', flush=True)


    if __name__ == '__main__':
        import sys
        from pathlib import Path

        if len(sys.argv) != 4:
            print(f'Usage: {Path(__file__).stem} <client_id> <client_secret> <user_agent>')
            sys.exit(1)
        client_id = sys.argv[1]
        client_secret = sys.argv[2]
        user_agent = sys.argv[3]
        recreate_problem(client_id, client_secret, user_agent)




Discussion:
I'm getting a `RecursionError` when I try something as simple as `reddit.subreddit('tifu').emoji`. I suspect there's a problem with `__repr__` and `__str__`. I'll submit a fix.

Thanks for bringing this to our attention!
I'm getting a `RecursionError` when I try something as simple as `reddit.subreddit('tifu').emoji`. I suspect there's a problem with `__repr__` and `__str__`. I'll submit a fix.

Thanks for bringing this to our attention!

Resolving patch:
diff --git a/praw/models/reddit/emoji.py b/praw/models/reddit/emoji.py
--- a/praw/models/reddit/emoji.py
+++ b/praw/models/reddit/emoji.py
@@ -53,11 +53,9 @@ def delete(self):
         self._reddit.request('DELETE', url)
 
 
-class SubredditEmoji(RedditBase):
+class SubredditEmoji(object):
     """Provides a set of functions to a Subreddit for emoji."""
 
-    __hash__ = RedditBase.__hash__
-
     def __getitem__(self, name):
         """Lazily return the Emoji for the subreddit named ``name``.
 
@@ -80,7 +78,7 @@ def __init__(self, subreddit):
 
         """
         self.subreddit = subreddit
-        super(SubredditEmoji, self).__init__(subreddit._reddit, None)
+        self._reddit = subreddit._reddit
 
     def __iter__(self):
         """Return a list of Emoji for the subreddit.


Test patch:
diff --git a/tests/unit/models/reddit/test_emoji.py b/tests/unit/models/reddit/test_emoji.py
--- a/tests/unit/models/reddit/test_emoji.py
+++ b/tests/unit/models/reddit/test_emoji.py
@@ -1,6 +1,7 @@
 import pickle
 
 from praw.models import Subreddit, Emoji
+from praw.models.reddit.emoji import SubredditEmoji
 
 from ... import UnitTest
 
@@ -72,3 +73,9 @@ def test_str(self):
         emoji = Emoji(self.reddit, subreddit=Subreddit(self.reddit, 'a'),
                       name='x')
         assert str(emoji) == 'x'
+
+
+class TestSubredditEmoji(UnitTest):
+    def test_repr(self):
+        se = SubredditEmoji(subreddit=Subreddit(self.reddit, 'a'))
+        assert repr(se)  # assert it has some repr