Skip to content

Conversation

s3rius
Copy link

@s3rius s3rius commented Sep 12, 2025

This PR adds more information on how to use the PyModule_GetState function, clarifying what argument should be passed.

At first glance, people might incorrectly think they need to pass a pointer to a state struct that the function will populate, but that is not the case.


📚 Documentation preview 📚: https://cpython-previews--138823.org.readthedocs.build/

@python-cla-bot
Copy link

python-cla-bot bot commented Sep 12, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Maybe like this?

allocated at module creation time, or ``NULL``. See
:c:member:`PyModuleDef.m_size`.
The module’s state can be stored in per‑module memory, which is obtained by calling this function.
This makes modules safe to use with sub‑interpreters.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
This makes modules safe to use with sub‑interpreters.

This is too specific.

Copy link
Author

@s3rius s3rius Sep 12, 2025

Choose a reason for hiding this comment

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

But isn't it the most useful feature of this function? Otherwise it doesn't makes sense to store per-module state.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe instead link to the PEP?

Copy link
Author

Choose a reason for hiding this comment

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

Added PEP link.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, but I disagree. PEPs shouldn't be used as documentation, because they're solely historical documents and don't receive updates when we change things. I think we should keep the "This makes modules safe to use with sub‑interpreters" sentence, because yes -- that's what this function is for.

Copy link
Contributor

@skirpichev skirpichev left a comment

Choose a reason for hiding this comment

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

I suggest leave things as is. There's no issue.

Maybe just add PEP link, indeed.

@s3rius
Copy link
Author

s3rius commented Sep 12, 2025

@skirpichev, @sobolevn. Intead of all the changes added link to the respective PEP. Can you please take a look once again?

@@ -96,6 +96,7 @@ Module Objects
allocated at module creation time, or ``NULL``. See
:c:member:`PyModuleDef.m_size`.

See :PEP:`489` for more details.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
See :PEP:`489` for more details.
See :pep:`489` for more details.

Copy link
Contributor

@skirpichev skirpichev left a comment

Choose a reason for hiding this comment

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

I'm still not sure if that's helpful. PEP 489 introduces a lot of API, why mention it just there? And also PyModule_GetState() was added by a different PEP, IIRIC.

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

Please don't solely link to the PEP. I think the original sentence ("This makes modules safe to use with sub‑interpreters") was fine.

@bedevere-app
Copy link

bedevere-app bot commented Sep 16, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

4 participants