Skip to content

gh-143715: Deprecate incomplete initialization of struct.Struct()#145580

Open
serhiy-storchaka wants to merge 29 commits intopython:mainfrom
serhiy-storchaka:deprecate-struct-init
Open

gh-143715: Deprecate incomplete initialization of struct.Struct()#145580
serhiy-storchaka wants to merge 29 commits intopython:mainfrom
serhiy-storchaka:deprecate-struct-init

Conversation

@serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Mar 6, 2026

  • Struct.__new__() will require a mandatory argument (format)
  • Calls of __init__() method on initialized Struct are deprecated

This is an evolution of #143659, but since virtually all code and test were rewritten I created a new PR.


📚 Documentation preview 📚: https://cpython-previews--145580.org.readthedocs.build/

skirpichev and others added 29 commits January 10, 2026 16:37
* ``Struct.__new__()`` will require a mandatory argument (format)
* Calls of ``__init__()`` method on initialized Struct are deprecated
This make format argument in the __init__() - optional.  If it's
missing, the object must be already initialized in __new__().
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This catch current pattern for Struct's subclassing like

class MyStruct(Struct):
    def __init__(self):
        super().__init__('>h')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants