Skip to content

bpo-46891: Fix creating a new instance of a module subclass with slots#31643

Merged
markshannon merged 2 commits intopython:mainfrom
faster-cpython:fix-new-module-with-slots
Mar 3, 2022
Merged

bpo-46891: Fix creating a new instance of a module subclass with slots#31643
markshannon merged 2 commits intopython:mainfrom
faster-cpython:fix-new-module-with-slots

Conversation

@markshannon
Copy link
Copy Markdown
Member

@markshannon markshannon commented Mar 2, 2022

Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I just have a minor question/remark on the test.

I'm happy to see the _PyType_AllocNoTrack() function that I added being used :-) Objects should only be tracked once their visit function can be safely called.

__slots__ = ("a", "b")

def __init__(self, name):
super().__init__(name)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this method? Maybe assign a and/or b attribute if you want to keep it? Or remove it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The important bit is having __slots__ in the class definition, I just checked and leaving out the __init__ method still reproduces the crash that this PR fixes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I approved the PR. @markshannon can decide to keep or remove the method, it doesn't really matter ;-)

@markshannon markshannon merged commit 751c9ed into python:main Mar 3, 2022
@markshannon markshannon deleted the fix-new-module-with-slots branch September 26, 2023 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants