gh-143715: deprecate incomplete initialization of struct.Struct()#143659
gh-143715: deprecate incomplete initialization of struct.Struct()#143659skirpichev wants to merge 24 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>
vstinner
left a comment
There was a problem hiding this comment.
LGTM.
What do you think @serhiy-storchaka?
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Please add a test for a new case mentioned in the issue. We can test if the type's tp_init and tp_new are the same to make more qualified decision.
serhiy-storchaka
left a comment
There was a problem hiding this comment.
And what about the following case?
class MyStruct(struct.Struct):
def __init__(self, arg):
super().__init__('>h')
my_struct = MyStruct('<h')
my_struct.pack(12345)There should emit a FutureWarning, because the current and the future code produce different results. MyStruct(5) should emit a DeprecationWarning, because it works in the current code, but will be error in future. ``MyStruct('>h')` should work without warnings.
Add *args, **kwargs to __init__() at line 798 and test with different arguments:
MyStruct(), MyStruct('>h'), MyStruct('<h'), MyStruct(5), MyStruct('<h', 5), MyStruct(format='<h'), etc.
Also add *args, **kwargs to __new__() in other example and test with different arguments.
Struct.__new__()will require a mandatory argument (format)__init__()method on initialized Struct are deprecated📚 Documentation preview 📚: https://cpython-previews--143659.org.readthedocs.build/