Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_struct.Struct should be immutable, missing Py_TPFLAGS_IMMUTABLETYPE flag #94254

Closed
kumaraditya303 opened this issue Jun 25, 2022 · 6 comments
Closed
Assignees
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@kumaraditya303
Copy link
Contributor

In Python 3.8:

Python 3.8.12 (default, Oct  4 2021, 15:56:52) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import _struct
>>> _struct.Struct.x = 1
Traceback (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 linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import _struct
>>> _struct.Struct.x=1
>>> _struct.Struct.x
1

This happens because _struct.Struct is missing Py_TPFLAGS_IMMUTABLETYPE in type flags.

cc: @erlend-aasland @encukou

@kumaraditya303 kumaraditya303 added type-bug An unexpected behavior, bug, or error extension-modules C modules in the Modules dir labels Jun 25, 2022
@kumaraditya303 kumaraditya303 self-assigned this Jun 25, 2022
@mdickinson
Copy link
Member

_struct.Struct should be immutable

Just wondering: why? Are there benefits to that immutability?

@mdickinson
Copy link
Member

Ah, I see there's related discussion at #88074.

@kumaraditya303
Copy link
Contributor Author

Yes, it was the previous issue 1 where most of this was fixed but some were left which should be fixed.
cc @gvanrossum

Footnotes

  1. https://github.com/python/cpython/issues/88074

@gvanrossum
Copy link
Member

Yeah, please fix.

@erlend-aasland
Copy link
Contributor

Thanks for noticing this, and thanks for the PR!

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 26, 2022
(cherry picked from commit 17ed560)

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 26, 2022
(cherry picked from commit 17ed560)

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
miss-islington added a commit that referenced this issue Jun 26, 2022
(cherry picked from commit 17ed560)

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
miss-islington added a commit that referenced this issue Jun 26, 2022
(cherry picked from commit 17ed560)

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
@kumaraditya303
Copy link
Contributor Author

Fixed by #94269

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants