Rename typing._collect_parameters (#118900)

Unfortunately, released versions of typing_extensions
monkeypatch this function without the extra parameter, which makes
it so things break badly if current main is used with typing_extensions.

Fortunately, the monkeypatching is not needed on Python 3.13, because CPython
now implements PEP 696. By renaming the function, we prevent the monkeypatch
from breaking typing.py internals.

We keep the old name (raising a DeprecationWarning) to help other external users who call it.
This commit is contained in:
Jelle Zijlstra 2024-05-10 09:55:49 -07:00 committed by GitHub
parent f5c6b9977a
commit ec9d12be96
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 8 deletions

View file

@ -45,7 +45,7 @@ import typing
import weakref
import types
from test.support import captured_stderr, cpython_only, infinite_recursion, requires_docstrings
from test.support import captured_stderr, cpython_only, infinite_recursion, requires_docstrings, import_helper
from test.typinganndata import ann_module695, mod_generics_cache, _typed_dict_helper
@ -6325,6 +6325,8 @@ class ForwardRefTests(BaseTestCase):
self.assertEqual(X | "x", Union[X, "x"])
self.assertEqual("x" | X, Union["x", X])
class InternalsTests(BaseTestCase):
def test_deprecation_for_no_type_params_passed_to__evaluate(self):
with self.assertWarnsRegex(
DeprecationWarning,
@ -6350,6 +6352,15 @@ class ForwardRefTests(BaseTestCase):
self.assertEqual(cm.filename, __file__)
def test_collect_parameters(self):
typing = import_helper.import_fresh_module("typing")
with self.assertWarnsRegex(
DeprecationWarning,
"The private _collect_parameters function is deprecated"
) as cm:
typing._collect_parameters
self.assertEqual(cm.filename, __file__)
@lru_cache()
def cached_func(x, y):