Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rename typing._collect_parameters#118900

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JelleZijlstra merged 6 commits intopython:mainfromJelleZijlstra:collectparams
May 10, 2024

Conversation

JelleZijlstra
Copy link
Member

function. 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.

% ~/py/cpython/python.exe test_typing_extensions.pyTraceback (most recent call last):  File "/Users/jelle/py/typing_extensions/src/test_typing_extensions.py", line 42, in <module>    from _typed_dict_test_helper import Foo, FooGeneric, VeryAnnotated  File "/Users/jelle/py/typing_extensions/src/_typed_dict_test_helper.py", line 17, in <module>    class FooGeneric(TypedDict, Generic[T]):                                ~~~~~~~^^^  File "/Users/jelle/py/cpython/Lib/typing.py", line 431, in inner    return func(*args, **kwds)  File "/Users/jelle/py/cpython/Lib/typing.py", line 1243, in _generic_class_getitem    return _GenericAlias(cls, args)  File "/Users/jelle/py/cpython/Lib/typing.py", line 1420, in __init__    self.__parameters__ = _collect_parameters(                          ~~~~~~~~~~~~~~~~~~~^        args,        ^^^^^        enforce_default_ordering=enforce_default_ordering,        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^    )    ^TypeError: _collect_parameters() got an unexpected keyword argument 'enforce_default_ordering'

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.

function. Unfortunately, released versions of typing_extensionsmonkeypatch this function without the extra parameter, which makesit so things break badly if current main is used with typing_extensions.```% ~/py/cpython/python.exe test_typing_extensions.pyTraceback (most recent call last):  File "/Users/jelle/py/typing_extensions/src/test_typing_extensions.py", line 42, in <module>    from _typed_dict_test_helper import Foo, FooGeneric, VeryAnnotated  File "/Users/jelle/py/typing_extensions/src/_typed_dict_test_helper.py", line 17, in <module>    class FooGeneric(TypedDict, Generic[T]):                                ~~~~~~~^^^  File "/Users/jelle/py/cpython/Lib/typing.py", line 431, in inner    return func(*args, **kwds)  File "/Users/jelle/py/cpython/Lib/typing.py", line 1243, in _generic_class_getitem    return _GenericAlias(cls, args)  File "/Users/jelle/py/cpython/Lib/typing.py", line 1420, in __init__    self.__parameters__ = _collect_parameters(                          ~~~~~~~~~~~~~~~~~~~^        args,        ^^^^^        enforce_default_ordering=enforce_default_ordering,        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^    )    ^TypeError: _collect_parameters() got an unexpected keyword argument 'enforce_default_ordering'```Fortunately, the monkeypatching is not needed on Python 3.13, because CPythonnow implements PEP 696. By renaming the function, we prevent the monkeypatchfrom breaking typing.py internals.
@AlexWaygood
Copy link
Member

AlexWaygood commentedMay 10, 2024
edited
Loading

There are some uses of this function in the wild, which this change would break...https://github.com/wyfo/apischema/blob/d48cc010c417e9c49db25b7a8683621b3c305b44/apischema/typing.py#L59-L62

And we could also fix the test failure over attyping_extensions with this diff:

--- a/src/typing_extensions.py+++ b/src/typing_extensions.py@@ -2836,7 +2836,8 @@ else:          return tuple(parameters)-    typing._collect_parameters = _collect_parameters+    if not _PEP_696_IMPLEMENTED:+        typing._collect_parameters = _collect_parameters

It's true that making a change in CPython rather thantyping_extensions has the advantage that already-released versions oftyping_extensions are fixed as well to-be-released versions oftyping_extensions. But I think already-released versions oftyping_extensions are badly broken anyway on Python 3.13, due to the error pointed out inpython/typing_extensions#377 (comment)

@JelleZijlstra
Copy link
MemberAuthor

But I think already-released versions oftyping_extensions are badly broken anyway on Python 3.13, due to the error pointed out inpython/typing_extensions#377 (comment)

I think that error shows up only if you usetyping_extensions.TypeVar though, while the error this PR fixes breaks any use of Generic aftertyping_extensions is imported, which feels much worse.

There are some uses of this function in the wild, which this change would break...https://github.com/wyfo/apischema/blob/d48cc010c417e9c49db25b7a8683621b3c305b44/apischema/typing.py#L59-L62

I think we could address this by keeping an alias_collect_parameters = _collect_type_parameters (or a wrapper function that raises DeprecationWarning).

AlexWaygood reacted with thumbs up emoji

@AlexWaygood
Copy link
Member

Okay, sounds reasonable.

I think we could address this by keeping an alias_collect_parameters = _collect_type_parameters (or a wrapper function that raises DeprecationWarning).

Or we could do this in the__getattr__ method down at the bottom? (Withdo_the_deprecation_warning() replaced by the appropriate logic to do a deprecation warning)

--- a/Lib/typing.py+++ b/Lib/typing.py@@ -3770,6 +3770,9 @@ def __getattr__(attr):     elif attr in {"ContextManager", "AsyncContextManager"}:         import contextlib         obj = _alias(getattr(contextlib, f"Abstract{attr}"), 2, name=attr, defaults=(bool | None,))+    elif attr == "_collect_parameters":+        do_the_deprecation_warning()+        return _collect_type_parameters     else:         raise AttributeError(f"module {__name__!r} has no attribute {attr!r}")     globals()[attr] = obj
JelleZijlstra reacted with thumbs up emoji

Copy link
Member

@AlexWaygoodAlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks!

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@JelleZijlstraJelleZijlstraenabled auto-merge (squash)May 10, 2024 16:21
@JelleZijlstraJelleZijlstra merged commitec9d12b intopython:mainMay 10, 2024
@miss-islington-app
Copy link

Thanks@JelleZijlstra for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestMay 10, 2024
Unfortunately, released versions of typing_extensionsmonkeypatch this function without the extra parameter, which makesit so things break badly if current main is used with typing_extensions.Fortunately, the monkeypatching is not needed on Python 3.13, because CPythonnow implements PEP 696. By renaming the function, we prevent the monkeypatchfrom breaking typing.py internals.We keep the old name (raising a DeprecationWarning) to help other external users who call it.(cherry picked from commitec9d12b)Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@bedevere-app
Copy link

GH-118917 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelMay 10, 2024
@JelleZijlstraJelleZijlstra deleted the collectparams branchMay 10, 2024 17:08
AlexWaygood pushed a commit that referenced this pull requestMay 10, 2024
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure⚠️⚠️⚠️

Hi! The buildbotAMD64 Ubuntu NoGIL 3.13 has failed when building commitb3074f0.

What do you need to do:

  1. Don't panic.
  2. Checkthe buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/1422/builds/9) and take a look at the build logs.
  4. Check if the failure is related to this commit (b3074f0) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/1422/builds/9

Failed tests:

  • test_eintr
  • test_math

Failed subtests:

  • test_flock -main.FNTLEINTRTest.test_flock
  • test_all - test.test_eintr.EINTRTests.test_all
  • test_wait_integer - test.test_multiprocessing_spawn.test_misc.TestWait.test_wait_integer
  • test_map_timeout - test.test_concurrent_futures.test_process_pool.ProcessPoolSpawnProcessPoolExecutorTest.test_map_timeout
  • test_lockf -main.FNTLEINTRTest.test_lockf

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):  File"/home/ubuntu/buildarea/3.13.itamaro-ubuntu-aws.nogil/build/Lib/test/_test_eintr.py", line532, intest_lockfself._lock(fcntl.lockf,"lockf")~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^  File"/home/ubuntu/buildarea/3.13.itamaro-ubuntu-aws.nogil/build/Lib/test/_test_eintr.py", line517, in_lockraiseException("failed to sync child in%.1f sec"% dt)Exception:failed to sync child in 300.5 secTraceback (most recent call last):  File"/home/ubuntu/buildarea/3.13.itamaro-ubuntu-aws.nogil/build/Lib/test/test_eintr.py", line17, intest_all    script_helper.run_test_script(script)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^  File"/home/ubuntu/buildarea/3.13.itamaro-ubuntu-aws.nogil/build/Lib/test/support/script_helper.py", line316, inrun_test_scriptraiseAssertionError(f"{name} failed")AssertionError:script _test_eintr.py failedTraceback (most recent call last):  File"/home/ubuntu/buildarea/3.13.itamaro-ubuntu-aws.nogil/build/Lib/test/_test_multiprocessing.py", line5176, intest_wait_integerself.assertLess(delta, expected+2)~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^AssertionError:5.133446088992059 not less than 5Traceback (most recent call last):  File"/home/ubuntu/buildarea/3.13.itamaro-ubuntu-aws.nogil/build/Lib/test/_test_eintr.py", line535, intest_flockself._lock(fcntl.flock,"flock")~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^  File"/home/ubuntu/buildarea/3.13.itamaro-ubuntu-aws.nogil/build/Lib/test/_test_eintr.py", line517, in_lockraiseException("failed to sync child in%.1f sec"% dt)Exception:failed to sync child in 300.5 secTraceback (test.test_zipimport.CompressedZipImportTestCase.testTraceback) ... okTraceback (test.test_zipimport.UncompressedZipImportTestCase.testTraceback) ... okTraceback (most recent call last):  File"/home/ubuntu/buildarea/3.13.itamaro-ubuntu-aws.nogil/build/Lib/test/test_concurrent_futures/executor.py", line71, intest_map_timeoutself.assertEqual([None,None], results)~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^AssertionError:Lists differ: [None, None] != []

estyxx pushed a commit to estyxx/cpython that referenced this pull requestJul 17, 2024
Unfortunately, released versions of typing_extensionsmonkeypatch this function without the extra parameter, which makesit so things break badly if current main is used with typing_extensions.Fortunately, the monkeypatching is not needed on Python 3.13, because CPythonnow implements PEP 696. By renaming the function, we prevent the monkeypatchfrom breaking typing.py internals.We keep the old name (raising a DeprecationWarning) to help other external users who call it.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@AlexWaygoodAlexWaygoodAlexWaygood approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@JelleZijlstra@AlexWaygood@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp