From 9b12b1b803d7b73640ab637a74a6f35f3fe9db21 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Wed, 23 Feb 2022 00:25:00 +0000 Subject: [PATCH] bpo-46522: fix concurrent.futures and io AttributeError messages (GH-30887) Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Andrew Svetlov --- Lib/_pyio.py | 2 +- Lib/concurrent/futures/__init__.py | 2 +- Lib/io.py | 2 +- .../next/Library/2022-01-25-15-31-04.bpo-46522.tYAlX4.rst | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2022-01-25-15-31-04.bpo-46522.tYAlX4.rst diff --git a/Lib/_pyio.py b/Lib/_pyio.py index d7119742b9d22b..8f20c5ed2abd5c 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -312,7 +312,7 @@ def __getattr__(name): global OpenWrapper OpenWrapper = open return OpenWrapper - raise AttributeError(name) + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") # In normal operation, both `UnsupportedOperation`s should be bound to the diff --git a/Lib/concurrent/futures/__init__.py b/Lib/concurrent/futures/__init__.py index d746aeac50a997..292e886d5a88ac 100644 --- a/Lib/concurrent/futures/__init__.py +++ b/Lib/concurrent/futures/__init__.py @@ -50,4 +50,4 @@ def __getattr__(name): ThreadPoolExecutor = te return te - raise AttributeError(f"module {__name__} has no attribute {name}") + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") diff --git a/Lib/io.py b/Lib/io.py index 2a6140c3dd5094..a205e00575f7e8 100644 --- a/Lib/io.py +++ b/Lib/io.py @@ -70,7 +70,7 @@ def __getattr__(name): global OpenWrapper OpenWrapper = open return OpenWrapper - raise AttributeError(name) + raise AttributeError("module {__name__!r} has no attribute {name!r}") # Pretend this exception was created here. diff --git a/Misc/NEWS.d/next/Library/2022-01-25-15-31-04.bpo-46522.tYAlX4.rst b/Misc/NEWS.d/next/Library/2022-01-25-15-31-04.bpo-46522.tYAlX4.rst new file mode 100644 index 00000000000000..999863adb9b314 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-01-25-15-31-04.bpo-46522.tYAlX4.rst @@ -0,0 +1 @@ +Make various module ``__getattr__`` AttributeErrors more closely match a typical AttributeError