gh-143715: Deprecate incomplete initialization of struct.Struct()#145580
gh-143715: Deprecate incomplete initialization of struct.Struct()#145580serhiy-storchaka merged 38 commits into
Conversation
* ``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')
skirpichev
left a comment
There was a problem hiding this comment.
This looks ok for me and have much better test coverage than my pr #143659.
Though, I worry that it's too complex: #143659 (comment)
Sorry, something went wrong.
serhiy-storchaka
left a comment
There was a problem hiding this comment.
The code is complex because the problem is complex.
We should minimize user inconvenience. If the code works in past and future versions, it should not emit warnings. There should be a way to write a warning-free code compatible with old versions (because you usually support more than one Python versions), and it should be valid in future versions.
If ignore this, we could just make a breaking change without deprecation period. And we do this if there is no other way (for example, the format attribute is now a string, not a bytes object like in older versions -- it was impossible to make this change not abrupt).
Sorry, something went wrong.
As I said in #143659 (comment), this requirement looks too strong for me. To support several versions, people could also use CC @encukou, would you mind to review this pr? |
Sorry, something went wrong.
encukou
left a comment
There was a problem hiding this comment.
I like this approach! Thank you for caring about backwards compatibility!
Sorry, something went wrong.
Co-authored-by: Petr Viktorin <encukou@gmail.com>
|
About deprecation warning in the repeated Accidentally, this also makes the code a little bit simpler. |
Sorry, something went wrong.
7245630
into
python:main
Mar 12, 2026
…() (pythonGH-145580) * Struct.__new__() will require a mandatory argument (format) * Calls of __init__() method with a different format argument on initialized Struct are deprecated Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Struct.__new__()will require a mandatory argument (format)__init__()method on initialized Struct are deprecatedThis 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/