diff --git a/CHANGES.rst b/CHANGES.rst index a4eaa8bfd..1bd5431a3 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -9,6 +9,10 @@ Unreleased * Ability to submit image galleries with :meth:`.submit_gallery`. * Ability to specify modmail mute duration. +**Fixed** + +* An issue where performing a deepcopy on an :class:`.RedditBase` object will fail. + 7.1.0 (2020/07/16) ------------------ diff --git a/asyncpraw/models/reddit/base.py b/asyncpraw/models/reddit/base.py index dfb058869..fd305f40b 100644 --- a/asyncpraw/models/reddit/base.py +++ b/asyncpraw/models/reddit/base.py @@ -12,6 +12,10 @@ class RedditBase(AsyncPRAWBase): """Base class that represents actual Reddit objects.""" + def __deepcopy__(self, memodict={}): + """Only return the str attribute when performing a deepcopy.""" + return str(self) + @staticmethod def _url_parts(url): parsed = urlparse(url) diff --git a/tests/unit/models/reddit/test_base.py b/tests/unit/models/reddit/test_base.py new file mode 100644 index 000000000..9f3d23b9d --- /dev/null +++ b/tests/unit/models/reddit/test_base.py @@ -0,0 +1,16 @@ +"""Test classes from base.py.""" +from copy import deepcopy + +from asyncpraw.models.reddit.base import RedditBase +from ... import UnitTest + + +class TestRedditBase(UnitTest): + def test_deepcopy(self): + test_string = "test_string" + reddit_base = RedditBase( + None, _data={"title": test_string, "STR_FIELD": "title"} + ) + result = deepcopy(reddit_base) + assert isinstance(result, str) + assert result == test_string