summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-08-21 19:18:42 (GMT)
committerGitHub <noreply@github.com>2023-08-21 19:18:42 (GMT)
commitf04024d5880d0ff8888ae3899074aeddf5473bfc (patch)
tree48200c470b5c2be2f8ceda40577288c56b17fdbc
parent90a22eae452e2f50b7be9db81003e3e849480215 (diff)
downloadcpython-f04024d5880d0ff8888ae3899074aeddf5473bfc.zip
cpython-f04024d5880d0ff8888ae3899074aeddf5473bfc.tar.gz
cpython-f04024d5880d0ff8888ae3899074aeddf5473bfc.tar.bz2
[3.12] gh-107905: Test raising `__value__` for `TypeAliasType` (GH-107997) (#108217)
gh-107905: Test raising `__value__` for `TypeAliasType` (GH-107997) (cherry picked from commit 13104f3b7412dce9bf7cfd09bf2d6dad1f3cc2ed) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
-rw-r--r--Lib/test/test_type_aliases.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_type_aliases.py b/Lib/test/test_type_aliases.py
index 0ce97f5..8f0a998 100644
--- a/Lib/test/test_type_aliases.py
+++ b/Lib/test/test_type_aliases.py
@@ -168,6 +168,24 @@ class TypeParamsAliasValueTest(unittest.TestCase):
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):