Skip to content

Commit 4cc5e89

Browse files
authored
PYTHON-5362 WriteConcern repr should be eval-able (#2338)
1 parent 2374f38 commit 4cc5e89

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

doc/changelog.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
Changelog
22
=========
33

4+
Changes in Version 4.13.0 (2025/05/14)
5+
--------------------------------------
6+
7+
PyMongo 4.13 brings a number of changes including:
8+
9+
- Fixed a bug where :class:`pymongo.write_concern.WriteConcern` repr was not eval-able
10+
when using ``w="majority"``.
11+
12+
Issues Resolved
13+
...............
14+
15+
See the `PyMongo 4.13 release notes in JIRA`_ for the list of resolved issues
16+
in this release.
17+
18+
.. _PyMongo 4.13 release notes in JIRA: https://jira.mongodb.org/secure/ReleaseNote.jspa?projectId=10004&version=42509
419

520
Changes in Version 4.12.1 (2025/04/29)
621
--------------------------------------

pymongo/write_concern.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def acknowledged(self) -> bool:
127127

128128
def __repr__(self) -> str:
129129
return "WriteConcern({})".format(
130-
", ".join("{}={}".format(*kvt) for kvt in self.__document.items())
130+
", ".join(f"{k}={v!r}" for k, v in self.__document.items())
131131
)
132132

133133
def __eq__(self, other: Any) -> bool:

test/test_write_concern.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ def test_equality_incompatible_type(self):
6767
_fake_type = collections.namedtuple("NotAWriteConcern", ["document"]) # type: ignore
6868
self.assertNotEqual(WriteConcern(j=True), _fake_type({"j": True}))
6969

70+
def assertRepr(self, obj):
71+
new_obj = eval(repr(obj))
72+
self.assertEqual(type(new_obj), type(obj))
73+
self.assertEqual(repr(new_obj), repr(obj))
74+
75+
def test_repr(self):
76+
concern = WriteConcern(j=True, wtimeout=3000, w="majority", fsync=False)
77+
self.assertRepr(concern)
78+
self.assertEqual(
79+
repr(concern),
80+
"WriteConcern(wtimeout=3000, j=True, fsync=False, w='majority')",
81+
)
82+
7083

7184
if __name__ == "__main__":
7285
unittest.main()

0 commit comments

Comments
 (0)