From 0a0f49121a93169a5fbb9bac5c5541e17ff5e57a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20M=C3=A9ndez=20Bravo?= Date: Fri, 6 May 2022 18:10:10 -0600 Subject: [PATCH] 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 --- pep-0690.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pep-0690.rst b/pep-0690.rst index 6e638d9ec..2c2b8d656 100644 --- a/pep-0690.rst +++ b/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 =======================