| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
* ``Struct.__new__()`` will require a mandatory argument (format) * Calls of ``__init__()`` method on initialized Struct are deprecated
|
The evil plan is to remove custom Struct.__init__() method and move all initialization logic to the Struct.__new__(). Something, that was done by #94532 before. |
Sorry, something went wrong.
There was a problem hiding this comment.
Sorry, something went wrong.
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>
@serhiy-storchaka, this seems too complex for me. Look, we are going to that state: #94532. (I did a working patch to play with in skirpichev#17.) That means, eventually the Struct's __init__() will be no-op (and accept any arguments). Thus, we should warn users on this pattern: explicit call of the __init__() on an object of some Struct subclass. Just in all above examples. Does make sense for you? CC @vstinner |
Sorry, something went wrong.
This catch current pattern for Struct's subclassing like
class MyStruct(Struct):
def __init__(self):
super().__init__('>h')
Co-authored-by: Victor Stinner <vstinner@python.org>
There was a problem hiding this comment.
The overall change LGTM, but I have a few more minor comments.
Sorry, something went wrong.
Co-authored-by: Victor Stinner <vstinner@python.org>
There was a problem hiding this comment.
LGTM.
@serhiy-storchaka: Do you want to review this change?
Sorry, something went wrong.
|
I tried to fix corner cases, but since all code and tests were rewritten, I created a separate PR #145580. |
Sorry, something went wrong.
|
Ah, I forgot that format is positional or keyword argument. Will adapt code a bit. |
Sorry, something went wrong.
|
Apparently, this overflowed my bandwidth. I'm happy to see the issue is in more qualified hands now. The #145580 looks ok for me, but I worry that such approach is much more complex just to satisfy the constraint:
Transition could be handled with, say: if sys.version_info < (3, 15):
# old idiom:
class MyStruct(struct.Struct):
def __init__(self):
super().__init__('>h')
else:
# new idiom:
class MyStruct2(struct.Struct):
def __new__(cls):
self = super().__new__(cls, '>h')
return selfThanks for reviews! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
📚 Documentation preview 📚: https://cpython-previews--143659.org.readthedocs.build/