Skip to content

Commit 7bb8f18

Browse files
committed
Ensure that concurrent.future.Future has the right module name (e.g. in exceptions)
1 parent a7bb524 commit 7bb8f18

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

Lib/concurrent/futures/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,13 @@
4747
__all__.append('InterpreterPoolExecutor')
4848

4949

50+
# Set __module__ to the public location rather than the private _base module.
51+
Future.__module__ = 'concurrent.futures'
52+
Executor.__module__ = 'concurrent.futures'
53+
CancelledError.__module__ = 'concurrent.futures'
54+
InvalidStateError.__module__ = 'concurrent.futures'
55+
BrokenExecutor.__module__ = 'concurrent.futures'
56+
57+
5058
def __dir__():
5159
return __all__ + ['__author__', '__doc__']

Lib/test/test_concurrent_futures/test_future.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,20 @@ def test_repr(self):
135135
repr(SUCCESSFUL_FUTURE),
136136
'<Future at 0x[0-9a-f]+ state=finished returned int>')
137137

138+
def test_class_str(self):
139+
self.assertEqual(str(futures.Future),
140+
"<class 'concurrent.futures.Future'>")
141+
self.assertEqual(str(futures.CancelledError),
142+
"<class 'concurrent.futures.CancelledError'>")
143+
self.assertEqual(str(futures.TimeoutError),
144+
"<class 'TimeoutError'>")
145+
self.assertEqual(str(futures.Executor),
146+
"<class 'concurrent.futures.Executor'>")
147+
self.assertEqual(str(futures.InvalidStateError),
148+
"<class 'concurrent.futures.InvalidStateError'>")
149+
self.assertEqual(str(futures.BrokenExecutor),
150+
"<class 'concurrent.futures.BrokenExecutor'>")
151+
138152
def test_cancel(self):
139153
f1 = create_future(state=PENDING)
140154
f2 = create_future(state=RUNNING)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Set ``__module__`` to ``concurrent.futures`` on the public classes
2+
``Future``, ``Executor``, ``CancelledError``, ``InvalidStateError`` and
3+
``BrokenExecutor``, so their ``repr`` and exception tracebacks reference the
4+
documented public location rather than the private ``concurrent.futures._base``
5+
module.

0 commit comments

Comments
 (0)