gh-118418: Deprecate failing to pass a value to the *type_params* parameter of some private typing APIs (#118695)

This commit is contained in:
Alex Waygood 2024-05-07 12:12:28 +01:00 committed by GitHub
parent 6f768b71ba
commit 0f8a07d158
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 61 additions and 11 deletions

View file

@ -6308,6 +6308,31 @@ class ForwardRefTests(BaseTestCase):
self.assertEqual(X | "x", Union[X, "x"])
self.assertEqual("x" | X, Union["x", X])
def test_deprecation_for_no_type_params_passed_to__evaluate(self):
with self.assertWarnsRegex(
DeprecationWarning,
(
"Failing to pass a value to the 'type_params' parameter "
"of 'typing._eval_type' is deprecated"
)
) as cm:
self.assertEqual(typing._eval_type(list["int"], globals(), {}), list[int])
self.assertEqual(cm.filename, __file__)
f = ForwardRef("int")
with self.assertWarnsRegex(
DeprecationWarning,
(
"Failing to pass a value to the 'type_params' parameter "
"of 'typing.ForwardRef._evaluate' is deprecated"
)
) as cm:
self.assertIs(f._evaluate(globals(), {}, recursive_guard=frozenset()), int)
self.assertEqual(cm.filename, __file__)
@lru_cache()
def cached_func(x, y):