[Python-checkins] gh-107905: Test raising `__value__` for `TypeAliasType` (#107997)
JelleZijlstra
webhook-mailer at python.org
Mon Aug 21 09:52:41 EDT 2023
https://github.com/python/cpython/commit/13104f3b7412dce9bf7cfd09bf2d6dad1f3cc2ed
commit: 13104f3b7412dce9bf7cfd09bf2d6dad1f3cc2ed
branch: main
author: Nikita Sobolev <mail at sobolevn.me>
committer: JelleZijlstra <jelle.zijlstra at gmail.com>
date: 2023-08-21T13:52:37Z
summary:
gh-107905: Test raising `__value__` for `TypeAliasType` (#107997)
files:
M Lib/test/test_type_aliases.py
diff --git a/Lib/test/test_type_aliases.py b/Lib/test/test_type_aliases.py
index 0ce97f57de686..8f0a998e1f3dc 100644
--- a/Lib/test/test_type_aliases.py
+++ b/Lib/test/test_type_aliases.py
@@ -168,6 +168,24 @@ def test_recursive_repr(self):
self.assertEqual(repr(GenericRecursive[GenericRecursive[int]]),
"GenericRecursive[GenericRecursive[int]]")
+ def test_raising(self):
+ type MissingName = list[_My_X]
+ with self.assertRaisesRegex(
+ NameError,
+ "cannot access free variable '_My_X' where it is not associated with a value",
+ ):
+ MissingName.__value__
+ _My_X = int
+ self.assertEqual(MissingName.__value__, list[int])
+ del _My_X
+ # Cache should still work:
+ self.assertEqual(MissingName.__value__, list[int])
+
+ # Explicit exception:
+ type ExprException = 1 / 0
+ with self.assertRaises(ZeroDivisionError):
+ ExprException.__value__
+
class TypeAliasConstructorTest(unittest.TestCase):
def test_basic(self):
More information about the Python-checkins
mailing list