Skip to content

Commit

Permalink
Sort praw.models.reddit.mixins.MessageableMixin.message arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
LilSpazJoekp committed Jan 6, 2022
1 parent e3def47 commit 1c3a2ca
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
17 changes: 10 additions & 7 deletions praw/models/reddit/mixins/messageable.py
Expand Up @@ -2,6 +2,7 @@
from typing import TYPE_CHECKING, Optional, Union

from ....const import API_PATH
from ....util import _deprecate_args

if TYPE_CHECKING: # pragma: no cover
import praw
Expand All @@ -10,16 +11,16 @@
class MessageableMixin:
"""Interface for classes that can be messaged."""

@_deprecate_args("subject", "message", "from_subreddit")
def message(
self,
subject: str,
message: str,
*,
from_subreddit: Optional[Union["praw.models.Subreddit", str]] = None,
message: str,
subject: str,
):
"""Send a message to a :class:`.Redditor` or a :class:`.Subreddit`'s moderators (modmail).
:param subject: The subject of the message.
:param message: The message content.
:param from_subreddit: A :class:`.Subreddit` instance or string to send the
message from. When provided, messages are sent from the subreddit rather
than from the authenticated user.
Expand All @@ -29,26 +30,28 @@ def message(
The authenticated user must be a moderator of the subreddit and have the
``mail`` moderator permission.
:param message: The message content.
:param subject: The subject of the message.
For example, to send a private message to u/spez, try:
.. code-block:: python
reddit.redditor("spez").message("TEST", "test message from PRAW")
reddit.redditor("spez").message(subject="TEST", message="test message from PRAW")
To send a message to u/spez from the moderators of r/test try:
.. code-block:: python
reddit.redditor("spez").message(
"TEST", "test message from r/test", from_subreddit="test"
subject="TEST", message="test message from r/test", from_subreddit="test"
)
To send a message to the moderators of r/test, try:
.. code-block:: python
reddit.subreddit("test").message("TEST", "test PM from PRAW")
reddit.subreddit("test").message(subject="TEST", message="test PM from PRAW")
"""
data = {
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/models/reddit/test_redditor.py
Expand Up @@ -61,16 +61,16 @@ def test_message(self, _):
self.reddit.read_only = False
with self.use_cassette():
redditor = self.reddit.redditor("subreddit_stats")
redditor.message("PRAW test", "This is a test from PRAW")
redditor.message(subject="PRAW test", message="This is a test from PRAW")

@mock.patch("time.sleep", return_value=None)
def test_message_from_subreddit(self, _):
self.reddit.read_only = False
with self.use_cassette():
redditor = self.reddit.redditor("subreddit_stats")
redditor.message(
"PRAW test",
"This is a test from PRAW",
subject="PRAW test",
message="This is a test from PRAW",
from_subreddit=pytest.placeholders.test_subreddit,
)

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/models/reddit/test_subreddit.py
Expand Up @@ -159,7 +159,7 @@ def test_message(self, _):
self.reddit.read_only = False
with self.use_cassette():
subreddit = self.reddit.subreddit(pytest.placeholders.test_subreddit)
subreddit.message("Test from PRAW", message="Test content")
subreddit.message(subject="Test from PRAW", message="Test content")

@mock.patch("time.sleep", return_value=None)
def test_post_requirements(self, _):
Expand Down

0 comments on commit 1c3a2ca

Please sign in to comment.