I think the edits do a decent job of cutting the PEP down to just the bits that everyone has agreed are a good (or at least reasonable) idea, but I’m still not entirely clear on the way the new API is expected to interact with the PEP 587 preconfiguration API.
I don’t think the note in the abstract about “This PEP unifies also the
configuration of the Python preinitialization and the Python
initialization in a single API.” is true anymore (from what I can see in the PEP use_environment
is the only preconfiguration field that can be set directly).
The values of the other preconfiguration fields are dictated by the choice of creating a Python
configuration or an Isolated
configuration (while the parallels with PEP 587 are useful, I do wonder if it might be better to give these names like PyInitConfig_AsPythonCLI
and PyInitConfig_AsEmbeddedRuntime
to more clearly convey when an embedder will want one base config set over the other. Embedders aren’t likely to know off the top of their heads if they want a “Python” config or an “Isolated” config, but they should know if they’re emulating the CPython CLI or embedding a CPython runtime in a larger application without exposing its CLI features).
However, what happens if the embedding app calls Py_PreInitialize
before calling either of the PyInitConfig_*
creation functions? My view is that this should work, with those pre-init settings being retained for use in the PEP 741 configuration. The preinit struct is far more stable than the main config struct, and it doesn’t have any strings in it, so it’s just generally much less of a hassle to deal with. For most purposes “Python CLI or embedded runtime?” will cover any preinit configuration needed, and for those rare cases where more control is needed, the PEP 587 preinit API isn’t currently planned to go anywhere.
I also feel like “potentially compatible with the stable ABI” is worth mentioning in the rationale (the abstract still mentions it, after all). Having the option available is a genuine benefit of the updated design, even if we don’t think it’s worth actually following through on the possibility in the near term.
The omission of the Locale
and WStr
APIs feels like it should go in a “Deferred Ideas” section rather than being omitted entirely or outright rejected. Those functions have clear utility in some embedding use cases, the debate is around whether it’s CPython’s responsibility to offer solutions for dealing with them. PEP 587 was heavily influenced by CPython’s own needs, hence settling on wstr lists as the most straightforward way to build a system that could readily handle data being pulled from either *nix APIs with dubious encodings or from Windows wstr APIs, while PEP 741 is more focused on embedding use cases where all of the configuration data is coming directly from the embedding application itself.
It does raise the question that if the Locale and WStr APIs are being omitted, perhaps PyInitConfig_CreatePython
should also be excluded? Emulating the CPython CLI is an intrinsically higher coupling activity than just embedding an isolated CPython runtime for use within the embedding application, so it actually seems reasonable to me to leave that use case to the lower level PEP 587 APIs (at least initially, anyway).