As the following REPL session seems to show, zoneinfo support in version 1.5.0 is incomplete. The standalone dump of ZoneInfo works, but when constructing a datetime with tzinfo , the nested dump doesn't work.
>>> import jsons
>>> from zoneinfo import ZoneInfo
>>> info = ZoneInfo(key='America/Los_Angeles')
>>> di = jsons.dump(info)
>>> di
{'key': 'America/Los_Angeles'}
>>> from datetime import datetime, timedelta
>>> dt = datetime(2020, 10, 31, 12, tzinfo=ZoneInfo("America/Los_Angeles"))
>>> jdt = jsons.dump(dt)
Traceback (most recent call last):
File "C:\Users\jeff1\Documents\projects\git\cdk\r53\.venv\lib\site-packages\jsons\_dump_impl.py", line 60, in _do_dump
result = serializer(obj, cls=cls, **kwargs)
File "C:\Users\jeff1\Documents\projects\git\cdk\r53\.venv\lib\site-packages\jsons\serializers\default_datetime.py", line 21, in default_datetime_serializer
return to_str(obj, strip_microseconds, kwargs['fork_inst'],
File "C:\Users\jeff1\Documents\projects\git\cdk\r53\.venv\lib\site-packages\jsons\_datetime_impl.py", line 20, in to_str
offset = get_offset_str(dt, fork_inst)
File "C:\Users\jeff1\Documents\projects\git\cdk\r53\.venv\lib\site-packages\jsons\_datetime_impl.py", line 37, in get_offset_str
result = _datetime_offset_str(obj, fork_inst)
File "C:\Users\jeff1\Documents\projects\git\cdk\r53\.venv\lib\site-packages\jsons\_datetime_impl.py", line 76, in _datetime_offset_str
tdelta = tzone.utcoffset(None) or tzone.adjusted_offset
AttributeError: 'zoneinfo.ZoneInfo' object has no attribute 'adjusted_offset'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\jeff1\Documents\projects\git\cdk\r53\.venv\lib\site-packages\jsons\_dump_impl.py", line 55, in dump
return _do_dump(obj, serializer, cls, initial, kwargs_)
File "C:\Users\jeff1\Documents\projects\git\cdk\r53\.venv\lib\site-packages\jsons\_dump_impl.py", line 66, in _do_dump
raise SerializationError(str(err)) from err
jsons.exceptions.SerializationError: 'zoneinfo.ZoneInfo' object has no attribute 'adjusted_offset'
As the following REPL session seems to show,
zoneinfo
support in version1.5.0
is incomplete. The standalonedump
ofZoneInfo
works, but when constructing adatetime
withtzinfo
, the nested dump doesn't work.