Skip to content

[3.12] gh-107905: Test raising __value__ for TypeAliasType (GH-107997) #108217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Lib/test/test_type_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down