PYTHON-4690 Add repr for FixedOffset eg FixedOffset(datetime.timedelta(seconds=3600), '+60')) (#1806)
This commit is contained in:
parent
4dde30147c
commit
4eae7d2d94
@ -39,6 +39,9 @@ class FixedOffset(tzinfo):
|
|||||||
def __getinitargs__(self) -> Tuple[timedelta, str]:
|
def __getinitargs__(self) -> Tuple[timedelta, str]:
|
||||||
return self.__offset, self.__name
|
return self.__offset, self.__name
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return f"{self.__class__.__name__}({self.__offset!r}, {self.__name!r})"
|
||||||
|
|
||||||
def utcoffset(self, dt: Optional[datetime]) -> timedelta:
|
def utcoffset(self, dt: Optional[datetime]) -> timedelta:
|
||||||
return self.__offset
|
return self.__offset
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,7 @@ PyMongo 4.9 brings a number of improvements including:
|
|||||||
:class:`~pymongo.operations.DeleteOne`, and
|
:class:`~pymongo.operations.DeleteOne`, and
|
||||||
:class:`~pymongo.operations.DeleteMany` operations, so
|
:class:`~pymongo.operations.DeleteMany` operations, so
|
||||||
they can be used in the new :meth:`~pymongo.mongo_client.MongoClient.bulk_write`.
|
they can be used in the new :meth:`~pymongo.mongo_client.MongoClient.bulk_write`.
|
||||||
|
- Added :func:`repr` support to :class:`bson.tz_util.FixedOffset`.
|
||||||
|
|
||||||
Issues Resolved
|
Issues Resolved
|
||||||
...............
|
...............
|
||||||
|
|||||||
@ -1019,6 +1019,10 @@ class TestCodecOptions(unittest.TestCase):
|
|||||||
tz = FixedOffset(42, "forty-two")
|
tz = FixedOffset(42, "forty-two")
|
||||||
self.assertRaises(ValueError, CodecOptions, tzinfo=tz)
|
self.assertRaises(ValueError, CodecOptions, tzinfo=tz)
|
||||||
self.assertEqual(tz, CodecOptions(tz_aware=True, tzinfo=tz).tzinfo)
|
self.assertEqual(tz, CodecOptions(tz_aware=True, tzinfo=tz).tzinfo)
|
||||||
|
self.assertEqual(repr(tz), "FixedOffset(datetime.timedelta(seconds=2520), 'forty-two')")
|
||||||
|
self.assertEqual(
|
||||||
|
repr(eval(repr(tz))), "FixedOffset(datetime.timedelta(seconds=2520), 'forty-two')"
|
||||||
|
)
|
||||||
|
|
||||||
def test_codec_options_repr(self):
|
def test_codec_options_repr(self):
|
||||||
r = (
|
r = (
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user