-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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
bpo-1635741: Port _collections extension module to multiphase initialization(PEP 489) #18066
Conversation
Perhaps Nick can review this one. I'm unclear on whether this PR actually makes anything better (something you can do afterwards that you couldn't do before). I was not under the impression that PEP 489 required that every single module change its initialization code. If there is an improvement and Nick approved, I have no objection to this going forward. |
The key benefits that multi-phase initialisation brings to a relatively straightforward extension module like If we look at one of the types that collections defines, we see that we normally can't persuade the interpreter to re-create it, even if we're accessing the module from a subinterpreter:
Even trashing the module to the point where reload doesn't work any more, still doesn't clear the hidden module state cache (the object ID only changed from above because this is a different REPL session):
By contrast, once it has migrated to multi-phase initialisation, then reloading it (or loading it in a subinterpreter) will actually recreate the contents, not just the containing dictionary and module metadata. (cc @ericsnowcurrently @encukou in case I missed something above). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Regarding the codecov complaints: I believe most of the issue is the fact we don't explicitly test the error returns from module initialisation functions. That's not going to change any time soon (and likely not ever). However, I did find a bug in our code coverage configuration, where news file snippets are being counted as uncovered: #18194 |
Nick, thank you for your explanation. petr have leave a comment in #18032. And i find the historical email have discussed this problem too: |
Reviewing the comments on #18032 reminded me that there is an issue impacting the That means migrating modules that use that macro is currently a bit messy, as we don't have a subinterpreter-friendly replacement that is anywhere near as tidy. (See 5a7d2e1 for an example of converting a module away from using it). Given that the collections module regularly uses In the meantime, continuing to use single-phase initialisation better reflects the actual status of the module. |
I missed the _Py_IDENTIFIER issue in my initial review
Given the This isn't a "we'll never port the collections module to multi-phase initialisation", but rather a matter of there being enough blockers to doing it right now that it makes sense to leave it alone until more of those blocking issues have been resolved. |
@shihai1991 Thanks for your work on this PR. You may find https://bugs.python.org/issue39465 interesting, as its an issue I just filed regarding the fact that |
@ncoghlan Of course, I'm interested in this bpo ;) |
If we have any modules that don't use |
https://bugs.python.org/issue1635741