praw-dev / praw

PRAW, an acronym for "Python Reddit API Wrapper", is a python package that allows for simple access to Reddit's API.
http://praw.readthedocs.io/
BSD 2-Clause "Simplified" License
3.53k stars 462 forks source link

SubredditHelper.__call__() got an unexpected keyword argument 'other_subreddits' #2006

Closed ghost closed 9 months ago

ghost commented 11 months ago

Describe the Bug

Encountered this error when attempting to subscribe to multiple subreddits at once:

TypeError("SubredditHelper.call() got an unexpected keyword argument 'other_subreddits'")

The docs mention that the other_subreddits parameter is accepted.

The Reddit docs also mention that the same parameter (called sr / sr_name on their end) is still accepted.

However, praw/models/reddit/subreddit.py and the error message above seem to indicate this has been deprecated within PRAW:

    @_deprecate_args("other_subreddits")
    def subscribe(self, *, other_subreddits: list[praw.models.Subreddit] | None = None):
        """Subscribe to the subreddit.

        :param other_subreddits: When provided, also subscribe to the provided list of
            subreddits.

        For example, to subscribe to r/test:

        .. code-block:: python

            reddit.subreddit("test").subscribe()

        """
        data = {
            "action": "sub",
            "skip_inital_defaults": True,
            "sr_name": self._subreddit_list(
                other_subreddits=other_subreddits, subreddit=self
            ),
        }
        self._reddit.post(API_PATH["subscribe"], data=data)

Desired Result

Code to reproduce the bug

# Works
reddit.subreddit('pics').subscribe()

# Doesn't work
reddit.subreddit('pics', other_subreddits = ['funny', 'aww']).subscribe()

My code does not include sensitive credentials

Relevant Logs

TypeError("SubredditHelper.__call__() got an unexpected keyword argument 'other_subreddits'")

This code has previously worked as intended

I'm not sure, I haven't used this code before.

Operating System/Environment

Windows 10

Python Version

3.12.0

PRAW Version

7.7.1

Links, references, and/or additional comments?

No response

LilSpazJoekp commented 11 months ago

However, praw/models/reddit/subreddit.py and the error message above seem to indicate this has been deprecated within PRAW:

The positional usage of other_subreddits in .subscribe() is deprecated not the parameter itself.

The .subscribe() method you're referencing is where you need to pass in other_subreddits=["funny", "aww"] like so:

reddit.subreddit('pics').subscribe(other_subreddits=["funny", "aww"])
ghost commented 11 months ago

Oh, duh! Thanks. Completely blanked on the fact that the parameter was listed for subscribe() and not subreddit().

github-actions[bot] commented 10 months ago

This issue is stale because it has been open for 30 days with no activity.

Remove the Stale label or comment or this will be closed in 30 days.

github-actions[bot] commented 9 months ago

This issue was closed because it has been stale for 30 days with no activity.