diff --git a/Lib/concurrent/futures/__init__.py b/Lib/concurrent/futures/__init__.py index 5d53a5ac50931d..a67e4f6a0a1888 100644 --- a/Lib/concurrent/futures/__init__.py +++ b/Lib/concurrent/futures/__init__.py @@ -47,5 +47,13 @@ __all__.append('InterpreterPoolExecutor') +# Set __module__ to the public location rather than the private _base module. +Future.__module__ = 'concurrent.futures' +Executor.__module__ = 'concurrent.futures' +CancelledError.__module__ = 'concurrent.futures' +InvalidStateError.__module__ = 'concurrent.futures' +BrokenExecutor.__module__ = 'concurrent.futures' + + def __dir__(): return __all__ + ['__author__', '__doc__'] diff --git a/Lib/test/test_concurrent_futures/test_future.py b/Lib/test/test_concurrent_futures/test_future.py index 06b11a3bacf13a..16c234be636b1d 100644 --- a/Lib/test/test_concurrent_futures/test_future.py +++ b/Lib/test/test_concurrent_futures/test_future.py @@ -135,6 +135,20 @@ def test_repr(self): repr(SUCCESSFUL_FUTURE), '') + def test_class_str(self): + self.assertEqual(str(futures.Future), + "") + self.assertEqual(str(futures.CancelledError), + "") + self.assertEqual(str(futures.TimeoutError), + "") + self.assertEqual(str(futures.Executor), + "") + self.assertEqual(str(futures.InvalidStateError), + "") + self.assertEqual(str(futures.BrokenExecutor), + "") + def test_cancel(self): f1 = create_future(state=PENDING) f2 = create_future(state=RUNNING) diff --git a/Misc/NEWS.d/next/Library/2026-08-18-04-30-00.gh-issue-115386.aB3xYz.rst b/Misc/NEWS.d/next/Library/2026-08-18-04-30-00.gh-issue-115386.aB3xYz.rst new file mode 100644 index 00000000000000..8760a07953f627 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-08-18-04-30-00.gh-issue-115386.aB3xYz.rst @@ -0,0 +1,5 @@ +Set ``__module__`` to ``concurrent.futures`` on the public classes +``Future``, ``Executor``, ``CancelledError``, ``InvalidStateError`` and +``BrokenExecutor``, so their ``repr`` and exception tracebacks reference the +documented public location rather than the private ``concurrent.futures._base`` +module.