Skip to content

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

Closed

Description

@kumaraditya303

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

Activity

  1. mdickinson commented on Jun 25, 2022

    @mdickinson
    Member

    _struct.Struct should be immutable

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

  2. mdickinson commented on Jun 25, 2022

    @mdickinson
    Member

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

  3. kumaraditya303 commented on Jun 25, 2022

    @kumaraditya303
    ContributorAuthor

    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 ↩

  4. gvanrossum commented on Jun 25, 2022

    @gvanrossum
    Member

    Yeah, please fix.

  5. erlend-aasland commented on Jun 25, 2022

    @erlend-aasland
    Contributor

    Thanks for noticing this, and thanks for the PR!

  6. added a commit that references this issue on Jun 26, 2022
  7. added 4 commits that reference this issue on Jun 26, 2022
  8. kumaraditya303 commented on Jun 26, 2022

    @kumaraditya303
    ContributorAuthor

    Fixed by #94269

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions