Open encukou opened 2 years ago
Thanks, Petr!
Relevant bpo's (I'll expand the list later):
Py_TPFLAGS_IMMUTABLETYPE
flag.Py_TPFLAGS_DISALLOW_INSTANTIATION
type flag.Related PEP's:
- list the behavior changes when static types are converted to heap types (mutability, pickleability, any more?), and document how to undo them when the new behavior is not better. Same for any other behavior changes related to changing existing code.
Expanding this list a little bit (mostly as a note to self):
Py_TPFLAGS_IMMUTABLETYPE
flag must be used for all new heap types in the stdlib.tp_new = NULL
, use the Py_TPFLAGS_DISALLOW_INSTANTIATION
flag when converting it to a heap type.Here's a draft of a ToC:
Subtitle: Applying PEP 630 to the standard library
Modules/xxlimited.c
Applying PEP 630 to the standard library
Please change to something like "Isolating modules in the standard library". Most people don't have PEP numbers memorized; having to look up part of a document name sucks :) Same for "PEP 573"→"module state access"
recap user benefits
Limited API & PySide aren't really relevant for the stdlib. If you're going for a new document, keep the rationale/motivation limited to stdlib itself. The reasons should be e.g. "Py_Finalize() doesn't clear all Python objects at exit" (bpo-1635741).
Modules/xxmodule.c must be ported sooner or later
It's already ported, see Modules/xxlimited.c. xxmodule should stay as example of the original API, as long as that's supported. But as a tutorial that can be followed any time, it could work well.
Please change to something like "Isolating modules in the standard library". Most people don't have PEP numbers memorized; having to look up part of a document name sucks :) Same for "PEP 573"→"module state access"
Good points :) I've updated the post.
If you're going for a new document [...]
I think it will work better as a separate document. It'll be too comprehensive to add to PEP 630. Two relatively short documents are better than one large document, IMO :)
It's already ported, see Modules/xxlimited.c.
Ah, thanks!
Checked some global static vars:
bool_repr
function: https://github.com/python/cpython/blob/62bf263a775f4444d8b5d5841cc09be3bd53e933/Objects/boolobject.c#L8-L9.refchain
maintained in interpreter would be better if ignore the code churn? https://github.com/python/cpython/blob/62bf263a775f4444d8b5d5841cc09be3bd53e933/Objects/object.c#L93I finally managed to allocate some time for this. I've gone back and forth a bit regarding the format and structure. So far, I think a short, informal, standalone document is fine for this. A draft is embedded in this post, but a PR is easier to review and collaborate with, so I figure I open a PR on this repo :)
Hi! Sorry about the delay, on my part this time. My life should be back to normal now :)
The draft looks OK. Perhaps it the goal should be to put it in the devguide, rather than a stand-alone document.
I think one thing missing from the guide is a more explicit note that not all types need to become heap types. If a type doesn't need the module state, it can be kept static. This might change depending on how/if GIL removal works, but it's too early in that project to know what will be needed.
The draft looks OK. Perhaps it the goal should be to put it in the devguide, rather than a stand-alone document.
The devguide sounds like a good place for such a document. That is, unless the SC thinks this calls for a stand-alone PEP, of course.
I think one thing missing from the guide is a more explicit note that not all types need to become heap types. [...] This might change depending on how/if GIL removal works, but it's too early in that project to know what will be needed.
So, we should note that as far as we know per now, not all types need become heap types, but that may change in the future.
If a type doesn't need the module state, it can be kept static.
Would that work correctly with multi-phase init?
So, we should note that as far as we know per now, not all types need become heap types, but that may change in the future.
It might change, but it also might not -- and not doing unnecessary changes helps limit the possible issues.
Would that work correctly with multi-phase init?
It should! If it doesn't, that's a pretty serious bug.
Ok, I'll update this in a couple of days hopefully. I'll update the PR on this repo. If the SC says an update to the devguide is enough, I'll create an issue and PR in that repo. For now, let's keep it here.
IMO, a PEP is in order. We need a PEP-like document, and we probably need SC approval, so let's go all the way. I'll take the existing document from the PR and work on it on it this week.
Great news!
PEP 630 has motivations and technical notes. What needs to be documented better is how both applies to stdlib. Specifically:
Whether that should be a new PEP or added to 630 doesn't matter much, IMO.
Then, any introduction of PEP 630 should be done deliberately, analyzing the pros and cons for each module separately. It should not be a mass change, and it should involve explaining the motivations & specific implications to module maintainers.