-
-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 3.13 compatibility #129
Conversation
return typing._eval_type(base_type, base_globals, _TYPING_LOCALS) | ||
if sys.version_info >= (3, 13): | ||
# noinspection PyProtectedMember | ||
return typing._eval_type(base_type, base_globals, _TYPING_LOCALS, type_params=()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benjjs Minor thing, can you pull this out to the top level? That way we won't need to do a python version check each time eval_forward_ref()
is called. Thanks!
if sys.version_info >= (3, 13):
_eval_type = functools.partial(typing._eval_type, type_params=())
else:
_eval_type = typing._eval_type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow-up, we can add this to utils/typing_compat.py
and import/use it instead:
# Check if currently running Python 3.13 or higher
PY313_OR_ABOVE = _PY_VERSION >= (3, 13)
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benjjs Minor thing, can you pull this out to the top level? That way we won't need to do a python version check each time
eval_forward_ref()
is called. Thanks!if sys.version_info >= (3, 13): _eval_type = functools.partial(typing._eval_type, type_params=()) else: _eval_type = typing._eval_type
This was not resolved, but its OK, I can do that. Simple fix.
from types import FunctionType | ||
|
||
|
||
def _set_qualname(cls, value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, thanks!
dataclass_wizard/serial_json.py
Outdated
@@ -10,6 +8,8 @@ | |||
from .dumpers import asdict | |||
from .loaders import fromdict, fromlist | |||
from .type_def import Decoder, Encoder, JSONObject, ListOfJSONObject | |||
# noinspection PyProtectedMember | |||
from .utils.compatibility import _create_fn, _set_new_attribute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if we can come up with a better name for the module. Maybe something like dataclasses_compat
? I think compatability
is a bit vague overall.
@benjjs Thanks so much for creating this PR! I recently upgraded my laptop to Python 3.13, and I also noticed that Dataclass Wizard breaks on import due to the errors mentioned in the PR. I feel that was my bad on importing hidden or private functions from a (builtin) module, which is a big no-no as I always say 😅 . Thanks again for your work and effort in creating this PR! I have added some comments, please let me know when you're able to look into the notes I added, and I will merge the bugfix for 3.13 once complete. Have a great day! |
Thanks for reviewing @rnag ! Addressed the above comments. |
Thanks @benjjs ! Everything looks good to go. I'll review/merge later today. |
Ok, looks good to go. Thanks! One minor change left, and I will work on the release. I actually dozed off yesterday night, so I was not able to do it then 😓 . Stay tuned for the release! |
Package is currently not compatible with Python 3.13 because it uses 2 functions from the
dataclasses
module that were removed from 3.12 to 3.13.To resolve this problem, I have simply pulled the relevant functions (along with one helper that was also removed) into the package. I've documented which version they were removed in and the original functions in 3.12 that they are copied from.
The only other change is to explicitly pass empty
type_params
totyping._eval_type()
, as leaving it implicit raises a warning in 3.13. Given that we previously did not supply this argument and the implicit default value was()
, explicitly passing()
will not change the behavior.There is almost certainly some more elegant way to do this that would involve removing the need for these functions in the first place, but my priority here was to add compatibility quickly and without modifying any underlying logic and hence potentially breaking things. If you (the commenter or reviewer) have the more elegant implementation, by all means put it up and let's do that instead!