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
GH-78724: Initialize struct.Struct in __new__ #94532
Conversation
|
If you want to schedule another build, you need to add the " |
|
Apologies for the silence; I'll get to this by the end of this weekend. |
|
LGTM too. To be on the safe side, I'd recommend not backporting this to 3.10, though it seems fine to backport to 3.11 if @pablogsal agrees. The bugs being fixed seem to be of the self-inflicted "well don't do that then" variety, so while it's definitely nice to have them fixed, it seems unlikely that they'll be blocking any real users of |
Yes, it can. This is fine, on Python 3.10: >>> import struct
>>> class Bob(struct.Struct):
... def __init__(self, format):
... super().__init__(format)
...
>>> b = Bob("!f")
>>> b.pack(2.3)
b'@\x1333'But it breaks on this branch: >>> import struct
>>> class Bob(struct.Struct):
... def __init__(self, format):
... super().__init__(format)
...
>>> b = Bob("!f")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in __init__
TypeError: object.__init__() takes exactly one argument (the instance to initialize)I'm finding it hard to imagine why anyone would be subclassing |
I think is ok to backport to 3.11 |
|
@kumaraditya303 Apologies, Kumar; I'm having second thoughts here. While common sense says that no-one will be subclassing Can you think of any ways that we could fix these bugs without the backward compatibility breakage? |
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
Thanks for the reviews!
I have made it backwards compatible by adding I have made the requested changes; please review again @mdickinson @ambv |
|
Thanks for making the requested changes! @mdickinson, @ambv: please review the changes made to this pull request. |
|
ping @mdickinson @ambv |
|
@kumaraditya303 Sorry for taking so long to get back to this. So the current code in this PR ends up duplicating some of the work: we end up calling Suggestion:
The reason for (2) here is that (1) is technically a breaking change, in that doing something like |
|
Alternatively, if we really want to try to stay perfectly backwards compatible (modulo the bugs being fixed, of course), we'd need to find a way re-organise the logic so that we don't end up calling |
|
Thanks for the review, I'll make the changes by next weekend. |
|
cc @mdickinson I have made the changes, I removed the code duplication and it is now only for 3.12+. |
|
If you want to schedule another build, you need to add the " |
|
The buildbots look happy. There are still three checks pending as of writing, but enough checks have passed to satisfy me. I'll merge now, but continue to watch those remaining three bots. |


Closes #75960
Closes #78724