gh-107905: Test raising `__value__` for `TypeAliasType` (#107997)

This commit is contained in:
Nikita Sobolev 2023-08-21 16:52:37 +03:00 committed by GitHub
parent 71962e5237
commit 13104f3b74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 0 deletions

View File

@ -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):