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:
parent
153cd9eb8b
commit
0a0f49121a
11
pep-0690.rst
11
pep-0690.rst
|
@ -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
|
||||
=======================
|
||||
|
|
Loading…
Reference in New Issue