◐ Shell
clean mode source ↗

gh-143715: deprecate incomplete initialization of struct.Struct() by skirpichev · Pull Request #143659 · python/cpython

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

@bedevere-app Bot mentioned this pull request

Jan 10, 2026

serhiy-storchaka

@skirpichev skirpichev changed the title gh-78724: deprecate incomplete initialization of struct.Struct() gh-143715: deprecate incomplete initialization of struct.Struct()

Jan 12, 2026
This make format argument in the __init__() - optional.  If it's
missing, the object must be already initialized in __new__().

vstinner

Co-authored-by: Victor Stinner <vstinner@python.org>
This catch current pattern for Struct's subclassing like

class MyStruct(Struct):
    def __init__(self):
        super().__init__('>h')

vstinner

Co-authored-by: Victor Stinner <vstinner@python.org>

vstinner

Co-authored-by: Victor Stinner <vstinner@python.org>

vstinner

@skirpichev skirpichev deleted the deprecate-struct-init-2/78724 branch

March 9, 2026 03:26