Uh oh!
There was an error while loading. Please reload this page.
gh-143715: deprecate incomplete initialization of struct.Struct() - #143659
gh-143715: deprecate incomplete initialization of struct.Struct()#143659skirpichev wants to merge 33 commits into
Conversation
* ``Struct.__new__()`` will require a mandatory argument (format) * Calls of ``__init__()`` method on initialized Struct are deprecated
skirpichev
commented
Jan 10, 2026
The evil plan is to remove custom |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This make format argument in the __init__() - optional. If it's missing, the object must be already initialized in __new__().
skirpichev
commented
Jan 13, 2026
CC @meadori per experts index. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Victor Stinner <vstinner@python.org>
skirpichev
commented
Feb 28, 2026
@serhiy-storchaka, this seems too complex for me. Look, we are going to that state: #94532. (I did a working patch to play with in skirpichev#17.) That means, eventually the Struct's Thus, we should warn users on this pattern: explicit call of the CC @vstinner |
This catch current pattern for Struct's subclassing like
class MyStruct(Struct):
def __init__(self):
super().__init__('>h')Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner
left a comment
There was a problem hiding this comment.
The overall change LGTM, but I have a few more minor comments.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner
left a comment
There was a problem hiding this comment.
LGTM.
@serhiy-storchaka: Do you want to review this change?
serhiy-storchaka
commented
Mar 6, 2026
I tried to fix corner cases, but since all code and tests were rewritten, I created a separate PR #145580. |
skirpichev
commented
Mar 7, 2026
Ah, I forgot that |
skirpichev
commented
Mar 9, 2026
Apparently, this overflowed my bandwidth. I'm happy to see the issue is in more qualified hands now. The #145580 looks ok for me, but I worry that such approach is much more complex just to satisfy the constraint:
Transition could be handled with, say: ifsys.version_info< (3, 15):
# old idiom:classMyStruct(struct.Struct):
def__init__(self):
super().__init__('>h')
else:
# new idiom:classMyStruct2(struct.Struct):
def__new__(cls):
self=super().__new__(cls, '>h')
returnselfThanks for reviews! |
Struct.__new__()will require a mandatory argument (format)__init__()method on initialized Struct are deprecated📚 Documentation preview 📚: https://cpython-previews--143659.org.readthedocs.build/