From 35d218438e34a3b02acfb83fae86903382abce80 Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Fri, 9 May 2025 11:55:00 -0700 Subject: [PATCH 1/2] PYTHON-5362 WriteConcern repr should be eval-able --- doc/changelog.rst | 15 +++++++++++++++ pymongo/write_concern.py | 2 +- test/test_write_concern.py | 13 +++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index 87918639cd..2edae40fb5 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -1,6 +1,21 @@ Changelog ========= +Changes in Version 4.13.0 (2025/05/29) +-------------------------------------- + +PyMongo 4.13 brings a number of changes including: + +- Fixed a bug where :class:`pymongo.write_concern.WriteConcern` repr was not eval-able + when using ``w="majority"``. + +Issues Resolved +............... + +See the `PyMongo 4.13 release notes in JIRA`_ for the list of resolved issues +in this release. + +.. _PyMongo 4.13 release notes in JIRA: https://jira.mongodb.org/secure/ReleaseNote.jspa?projectId=10004&version=42509 Changes in Version 4.12.1 (2025/04/29) -------------------------------------- diff --git a/pymongo/write_concern.py b/pymongo/write_concern.py index ff31c6730d..1f9da7af2e 100644 --- a/pymongo/write_concern.py +++ b/pymongo/write_concern.py @@ -127,7 +127,7 @@ def acknowledged(self) -> bool: def __repr__(self) -> str: return "WriteConcern({})".format( - ", ".join("{}={}".format(*kvt) for kvt in self.__document.items()) + ", ".join(f"{k}={v!r}" for k, v in self.__document.items()) ) def __eq__(self, other: Any) -> bool: diff --git a/test/test_write_concern.py b/test/test_write_concern.py index e22c7e7a8c..02a7cb6e5c 100644 --- a/test/test_write_concern.py +++ b/test/test_write_concern.py @@ -67,6 +67,19 @@ def test_equality_incompatible_type(self): _fake_type = collections.namedtuple("NotAWriteConcern", ["document"]) # type: ignore self.assertNotEqual(WriteConcern(j=True), _fake_type({"j": True})) + def assertRepr(self, obj): + new_obj = eval(repr(obj)) + self.assertEqual(type(new_obj), type(obj)) + self.assertEqual(repr(new_obj), repr(obj)) + + def test_repr(self): + concern = WriteConcern(j=True, wtimeout=3000, w="majority", fsync=False) + self.assertRepr(concern) + self.assertEqual( + repr(concern), + "WriteConcern(wtimeout=3000, j=True, fsync=False, w='majority')", + ) + if __name__ == "__main__": unittest.main() From a7b49f61898275cf71ff89bf4f0a48ad0554356c Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Fri, 9 May 2025 12:56:25 -0700 Subject: [PATCH 2/2] PYTHON-5362 Update scheduled release date --- doc/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index 2edae40fb5..9b0275dbd8 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -1,7 +1,7 @@ Changelog ========= -Changes in Version 4.13.0 (2025/05/29) +Changes in Version 4.13.0 (2025/05/14) -------------------------------------- PyMongo 4.13 brings a number of changes including: