PEP 690: Add flexibility to set_eager_imports() (#2571)

This adds a callback to the proposed `importlib.set_eager_imports()`.

Co-authored-by: Carl Meyer <carl@oddbird.net>
This commit is contained in:
Germán Méndez Bravo 2022-05-06 18:10:10 -06:00 committed by GitHub
parent 153cd9eb8b
commit 0a0f49121a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 0 deletions

View File

@ -231,6 +231,17 @@ a list of module names within which all imports will be eager::
The effect of this is also shallow: all imports within ``one.mod`` will be
eager, but not imports in all modules imported by ``one.mod``.
``set_eager_imports()`` can also take a callback which receives a module name and returns
whether imports within this module should be eager::
import re
from importlib import set_eager_imports
def eager_imports(name):
return re.match(r"foo\.[^.]+\.logger", name)
set_eager_imports(eager_imports)
Backwards Compatibility
=======================