Open
Conversation
350c456 to
1bd0372
Compare
17b139d to
f3cf727
Compare
77213f7 to
44b7e9b
Compare
27bd975 to
ae3ff4a
Compare
encukou
reviewed
Nov 14, 2022
Misc/stable_abi.toml
Outdated
| [function.PyDict_GetItemWithError] | ||
| added = '3.2' | ||
| [function.PyDict_IsLazyImport] | ||
| added = '3.12' |
There was a problem hiding this comment.
I don't think the new API should be in the Stable ABI, at least initially. The few (hopefully) modules that need these can import and call importlib functions.
Except for PyDict_NextWithError -- that's an improvement, independent of lazy imports. In fact, if you add it now I'd be happy to review the PR.
Also: new items are generally added at the end of stable_abi.toml.
|
This PR is stale because it has been open for 30 days with no activity. |
b7bcf2f to
2dcb749
Compare
48d2d19 to
ed3867c
Compare
e0ade32 to
c4494be
Compare
a678bb4 to
ccb30d7
Compare
Owner
Author
|
Rebased on top of CPython 3.12 stable. |
2e1acda to
1d8292c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lazy Imports
This implements Lazy Imports (PEP 690) on CPython main branch.
Most significant changes are in the following files:
Python/import.c- ~800 changesObjects/dictobject.c- 600 changesPython/ceval.c- ~300 changesObjects/lazyimportobject.c- ~200 new linesPython/import.cPyLazyImportObjectobjects._PyImport_LazyImportName(),_PyImport_EagerImportName(),_PyImport_ImportFrom(),PyImport_LoadLazyImport()and_imp._maybe_set_submodule_attribute()_imp) API:PyImport_SetLazyImports(),PyImport_SetLazyImportsInModule(),PyImport_IsLazyImportsEnabled()Objects/dictobject.cdict.keys(), etc. all maintain lazy values inside a dictionary._Py_dict_lookup()can now returnDKIX_VALUE_ERRORin case the resolution of a lazy object resulted in an error.*_keep_lazy/*KeepLazy(e.g._Py_dict_lookup_keep_lazy(),_PyDict_GetItemKeepLazy()) to force returning lazy objects without being resolved.PyDict_NextWithError(), which works the same way asPyDict_Next()with the exception it propagates any errors to the caller by returning0and setting an exception. Caller should useif (PyErr_Ocurred())to check for any errors._PyDict_HasLazyImports()PyDict_Next()andPyDict_NextWithError()resolve all the lazy objects in the dictionary if it has them and if the passedposis zero. Returns0on errors or if objects can't be resolved.PyDict_ResolveLazyImports()to resolve all lazy values in a dictionary.PyDict_Next(),dict.values(),dict.items()before starting to iterate through the dictionary, to ensure returned values are all resolved and that the dictionary doesn't mutate midway due to import side effects produced by resolving the values.dk_lazy_importsis to be able to make this call efficient for dictionaries without lazy values.PyDict_IsLazyImport()to check if a given key in a dictionary is a lazy object.Python/ceval.cEAGER_IMPORT_NAMEandIMPORT_NAMEto createPyLazyImportObjectobjects when the feature is enabled.import_name()andimport_from()were moved toPython/import.c, and mostly only renamed to_PyImport_EagerImportName()and_PyImport_ImportFrom(), respectively.Objects/lazyimportobject.cPyLazyImportObjectobject viaPyLazyImport_Type._PyLazyImport_NewModule(),_PyLazyImport_NewObject(),_PyLazyImport_GetName(),PyLazyImport_CheckExact()