-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[mypyc] Fixing __init__ for classes with @attr.s(slots=True). #18447
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
Conversation
JukkaL
left a comment
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.
Thanks for the PR! I have one suggestion.
mypyc/lib-rt/misc_ops.c
Outdated
| } | ||
| Py_DECREF(res); | ||
| // These attributes are added or modified by @attr.s(slots=True). | ||
| const char * const keys[] = {"__attrs_attrs__", "__attrs_own_setattr__", "__init__", ""}; |
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.
What about doing this only when using @attr.s, but not for a regular dataclass? E.g. pass a flag to the function indicating whether we are dealing with an attrs class.
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.
If my understanding is correct, CPython actually uses res but CPyDataclass_SleightOfHand(...) is throwing it away. So, copying attributes will probably reduce errors. Anyway, I have added a condition to copy attributes only for attr and attr-auto dataclasses. Please take a look.
JukkaL
left a comment
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.
Thanks for the update.
…#18447) Fixes mypyc/mypyc#1079. `@attr.s` generates a `__init__` function which was getting lost in `CPyDataclass_SleightOfHand`. This change copies the generated `__init__` function and a couple of others ones to maintain consistency with CPython.
Fixes mypyc/mypyc#1079.
@attr.sgenerates a__init__function which was getting lost inCPyDataclass_SleightOfHand. This change copies the generated__init__function and a couple of others ones to maintain consistency with CPython.