Skip to content

Commit bb937c2

Browse files
committed
chore: use lazy imports for concurrent.futures
This module has a manual lazy import hack using `__getattr__`. Now that lazy imports exist and cannot be disabled, this could use lazy imports instead. Key differences: this will now show up in sys.lazy_modules when accessed. Error messages should be a bit better without the wrapper `__getattr__` involved. That's the only differences I can think of. Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
1 parent 26696a6 commit bb937c2

1 file changed

Lines changed: 4 additions & 17 deletions

File tree

Lib/concurrent/futures/__init__.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
wait,
1818
as_completed)
1919

20+
lazy from .process import ProcessPoolExecutor
21+
lazy from .thread import ThreadPoolExecutor
22+
2023
__all__ = [
2124
'FIRST_COMPLETED',
2225
'FIRST_EXCEPTION',
@@ -40,26 +43,10 @@
4043
_interpreters = None
4144

4245
if _interpreters:
46+
lazy from .interpreter import InterpreterPoolExecutor
4347
__all__.append('InterpreterPoolExecutor')
4448

4549

4650
def __dir__():
4751
return __all__ + ['__author__', '__doc__']
4852

49-
50-
def __getattr__(name):
51-
global ProcessPoolExecutor, ThreadPoolExecutor, InterpreterPoolExecutor
52-
53-
if name == 'ProcessPoolExecutor':
54-
from .process import ProcessPoolExecutor
55-
return ProcessPoolExecutor
56-
57-
if name == 'ThreadPoolExecutor':
58-
from .thread import ThreadPoolExecutor
59-
return ThreadPoolExecutor
60-
61-
if _interpreters and name == 'InterpreterPoolExecutor':
62-
from .interpreter import InterpreterPoolExecutor
63-
return InterpreterPoolExecutor
64-
65-
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

0 commit comments

Comments
 (0)