ramonhagenaars / jsons

🐍 A Python lib for (de)serializing Python objects to/from JSON
https://jsons.readthedocs.io
MIT License
288 stars 40 forks source link

TypeError: Item in jsons.__all__ must be str, not function #172

Open nightan42643 opened 2 years ago

nightan42643 commented 2 years ago

Hey, there may be a bug in the __init__.py I think.

When I try from jsons import * I got an error: TypeError: Item in jsons.__all__ must be str, not function

And I checked your __init__.py and found below may be a bug:

if default_zone_info_serializer and default_zone_info_deserializer:
    from zoneinfo import ZoneInfo
    __all__.append(default_zone_info_serializer)
    __all__.append(default_zone_info_deserializer)
    set_serializer(default_zone_info_serializer, ZoneInfo)
    set_deserializer(default_zone_info_deserializer, ZoneInfo)

The two append line appended function into it, so I try to change it like below:

if default_zone_info_serializer and default_zone_info_deserializer:
    from zoneinfo import ZoneInfo
    __all__.append(default_zone_info_serializer.__name__)
    __all__.append(default_zone_info_deserializer.__name__)
    set_serializer(default_zone_info_serializer, ZoneInfo)
    set_deserializer(default_zone_info_deserializer, ZoneInfo)

After this change, from grammar can work normally.

ramonhagenaars commented 2 years ago

Thanks for reporting, that's a bug indeed!