You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
_struct.Struct should be immutable, missing Py_TPFLAGS_IMMUTABLETYPE flagΒ #94254
Python 3.8.12 (default, Oct 4 2021, 15:56:52) [GCC 9.3.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import _struct>>> _struct.Struct.x = 1Traceback (most recent call last): File "<stdin>", line 1, in <module>TypeError: can't set attributes of built-in/extension type 'Struct'>>>
On main:
Python 3.12.0a0 (heads/gh-94207-fix-struct-module-leak:9d41baebd0, Jun 25 2022, 07:23:49) [GCC 9.4.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import _struct>>> _struct.Struct.x=1>>> _struct.Struct.x1
This happens because _struct.Struct is missing Py_TPFLAGS_IMMUTABLETYPE in type flags.
Activity
mdickinson commentedon Jun 25, 2022
Just wondering: why? Are there benefits to that immutability?
mdickinson commentedon Jun 25, 2022
Ah, I see there's related discussion at #88074.
kumaraditya303 commentedon Jun 25, 2022
Yes, it was the previous issue 1 where most of this was fixed but some were left which should be fixed.
cc @gvanrossum
Footnotes
https://github.com/python/cpython/issues/88074 β©
gvanrossum commentedon Jun 25, 2022
Yeah, please fix.
erlend-aasland commentedon Jun 25, 2022
Thanks for noticing this, and thanks for the PR!
GH-94254: Make _struct module types immutable (#94269)
pythonGH-94254: Make _struct module types immutable (pythonGH-94269)
pythonGH-94254: Make _struct module types immutable (pythonGH-94269)
GH-94254: Make _struct module types immutable (GH-94269)
GH-94254: Make _struct module types immutable (GH-94269)
kumaraditya303 commentedon Jun 26, 2022
Fixed by #94269