gh-143715: deprecate incomplete initialization of struct.Struct()#143659
gh-143715: deprecate incomplete initialization of struct.Struct()#143659skirpichev wants to merge 33 commits intopython:mainfrom
Conversation
* ``Struct.__new__()`` will require a mandatory argument (format) * Calls of ``__init__()`` method on initialized Struct are deprecated
|
The evil plan is to remove custom |
This make format argument in the __init__() - optional. If it's missing, the object must be already initialized in __new__().
|
CC @meadori per experts index. |
Co-authored-by: Victor Stinner <vstinner@python.org>
@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')
Misc/NEWS.d/next/Library/2026-01-10-16-23-21.gh-issue-143715.HZrfSA.rst
Outdated
Show resolved
Hide resolved
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.
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?
|
I tried to fix corner cases, but since all code and tests were rewritten, I created a separate PR #145580. |
|
Ah, I forgot that |
Struct.__new__()will require a mandatory argument (format)__init__()method on initialized Struct are deprecated📚 Documentation preview 📚: https://cpython-previews--143659.org.readthedocs.build/