From 8a3cdc3768a8a31d380f9b200431a23886aa4082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20M=C3=A9ndez=20Bravo?= Date: Tue, 3 May 2022 12:35:44 -0700 Subject: [PATCH 1/4] PEP 960: Add flexibility to set_eager_imports() This adds a callback to the proposed `importlib.set_eager_imports()`. --- pep-0690.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pep-0690.rst b/pep-0690.rst index bf57d9fc741..085c94afcae 100644 --- a/pep-0690.rst +++ b/pep-0690.rst @@ -193,6 +193,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``. +Or a callback object which receives a module name returns whether the import +for such name 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 ======================= From 2302c6145c9b7954aafc550ece0234d38e2167fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20M=C3=A9ndez=20Bravo?= Date: Tue, 3 May 2022 12:47:22 -0700 Subject: [PATCH 2/4] Update pep-0690.rst Co-authored-by: Carl Meyer --- pep-0690.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pep-0690.rst b/pep-0690.rst index 085c94afcae..7209fdf6f01 100644 --- a/pep-0690.rst +++ b/pep-0690.rst @@ -193,8 +193,8 @@ 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``. -Or a callback object which receives a module name returns whether the import -for such name should be eager:: +``set_eager_imports()`` can instead take a callback which receives a module name and returns +whether the import of this module should be eager:: import re from importlib import set_eager_imports From df3c97cc559631546e892096174fe253b9051996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20M=C3=A9ndez=20Bravo?= Date: Tue, 3 May 2022 14:31:25 -0700 Subject: [PATCH 3/4] Update pep-0690.rst --- pep-0690.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pep-0690.rst b/pep-0690.rst index 7209fdf6f01..d9c7df5a485 100644 --- a/pep-0690.rst +++ b/pep-0690.rst @@ -193,7 +193,7 @@ 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 instead take a callback which receives a module name and returns +``set_eager_imports()`` can also take a callback which receives a module name and returns whether the import of this module should be eager:: import re From 70f8c8d35d445f2b2c3ba1513307d9e9b32ad5b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20M=C3=A9ndez=20Bravo?= Date: Tue, 3 May 2022 16:08:00 -0700 Subject: [PATCH 4/4] Update pep-0690.rst Co-authored-by: Carl Meyer --- pep-0690.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pep-0690.rst b/pep-0690.rst index d9c7df5a485..13a61743365 100644 --- a/pep-0690.rst +++ b/pep-0690.rst @@ -194,7 +194,7 @@ 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 the import of this module should be eager:: +whether imports within this module should be eager:: import re from importlib import set_eager_imports