summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_typing.py
diff options
context:
space:
mode:
authorJames Hilton-Balfe <gobot1234yt@gmail.com>2022-03-08 03:50:46 (GMT)
committerGitHub <noreply@github.com>2022-03-08 03:50:46 (GMT)
commitf391f9bf28f0bba7939d9f9e5a7a6396d2b0df62 (patch)
tree4151190384181dca5446c61e6dd7c3230739a6e0 /Lib/test/test_typing.py
parent50731297a9b6d57eec3b3f89522785b23f7b3e71 (diff)
downloadcpython-f391f9bf28f0bba7939d9f9e5a7a6396d2b0df62.zip
cpython-f391f9bf28f0bba7939d9f9e5a7a6396d2b0df62.tar.gz
cpython-f391f9bf28f0bba7939d9f9e5a7a6396d2b0df62.tar.bz2
bpo-46170: Improve the error message when subclassing NewType (GH-30268)
Co-authored-by: Alex Waygood <alex.waygood@gmail.com> Co-authored-by: Nikita Sobolev <mail@sobolevn.me> Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Diffstat (limited to 'Lib/test/test_typing.py')
-rw-r--r--Lib/test/test_typing.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 17d78cf..c76aa0a 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -4423,6 +4423,17 @@ class NewTypeTests:
)
exec(code, {})
+ def test_error_message_when_subclassing(self):
+ with self.assertRaisesRegex(
+ TypeError,
+ re.escape(
+ "Cannot subclass an instance of NewType. Perhaps you were looking for: "
+ "`ProUserId = NewType('ProUserId', UserId)`"
+ )
+ ):
+ class ProUserId(UserId):
+ ...
+
class NewTypePythonTests(NewTypeTests, BaseTestCase):
module = py_typing