Skip to content

Commit f04024d

Browse files
[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 13104f3) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
1 parent 90a22ea commit f04024d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Lib/test/test_type_aliases.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,24 @@ def test_recursive_repr(self):
168168
self.assertEqual(repr(GenericRecursive[GenericRecursive[int]]),
169169
"GenericRecursive[GenericRecursive[int]]")
170170

171+
def test_raising(self):
172+
type MissingName = list[_My_X]
173+
with self.assertRaisesRegex(
174+
NameError,
175+
"cannot access free variable '_My_X' where it is not associated with a value",
176+
):
177+
MissingName.__value__
178+
_My_X = int
179+
self.assertEqual(MissingName.__value__, list[int])
180+
del _My_X
181+
# Cache should still work:
182+
self.assertEqual(MissingName.__value__, list[int])
183+
184+
# Explicit exception:
185+
type ExprException = 1 / 0
186+
with self.assertRaises(ZeroDivisionError):
187+
ExprException.__value__
188+
171189

172190
class TypeAliasConstructorTest(unittest.TestCase):
173191
def test_basic(self):

0 commit comments

Comments
 (0)