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

@skirpichev

* ``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

@skirpichev

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

@skirpichev

@skirpichev

vstinner

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

@skirpichev

@skirpichev

@skirpichev

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>

@skirpichev

@skirpichev

vstinner

@skirpichev

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

vstinner

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

March 9, 2026 03:26