Visitar URL original
bpo-46644: Remove callable() requirement from typing._type_check by GBeauregard · Pull Request #31151 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20220520104147/https://github.com/python/cpython/pull/31151
Skip to content
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

bpo-46644: Remove callable() requirement from typing._type_check #31151

Merged
merged 9 commits into from Mar 12, 2022

Conversation

GBeauregard
Copy link
Contributor

@GBeauregard GBeauregard commented Feb 5, 2022 •

We remove tests that check for int literals. A check that a type isn't a tuple literal was added to cover cases like Final[int, str]. This codepath wasn't covered for TypeGuard so I added a test for it. Note we already disallow tuple types since things like Union[typeform]->typeform, but Union[typeform, typeform] -> Union[typeform, typeform].

https://bugs.python.org/issue46644

@GBeauregard GBeauregard marked this pull request as ready for review Feb 5, 2022
@GBeauregard GBeauregard changed the title bpo-46644: Remove type check callable bpo-46644: Remove callable() requirement from typing._type_check Feb 5, 2022
Lib/test/test_types.py Show resolved Hide resolved
Lib/test/test_typing.py Show resolved Hide resolved
@GBeauregard GBeauregard requested a review from JelleZijlstra Feb 6, 2022
@gvanrossum
Copy link
Member

@gvanrossum gvanrossum commented Feb 7, 2022

Since there is still discussion going on in bpo this should not yet be merged.

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

I still think we should move forward with this change and close the alternative #31159 (cc @gvanrossum @Fidget-Spinner @serhiy-storchaka). Being permissive in the typing.py runtime helps make innovation in the type system possible.

PEP 612 and 646 were difficult to implement in typing-extensions because of overly strict checks in typing.py (e.g. https://github.com/python/typing/blob/95c9c2bab2034f0359e8457360d93a288a65e55d/typing_extensions/src/typing_extensions.py#L1860, https://github.com/python/typing/blob/95c9c2bab2034f0359e8457360d93a288a65e55d/typing_extensions/src/typing_extensions.py#L1900). To make future PEPs easier to implement, I want to generally keep runtime checks in typing.py at a minimum. This PR removes a check that has been particularly problematic.

Copy link
Member

@gvanrossum gvanrossum left a comment

Yes, that’s fair. Godspeed!

@JelleZijlstra JelleZijlstra self-assigned this Mar 10, 2022
Copy link
Member

@Fidget-Spinner Fidget-Spinner left a comment

LGTM. Feel free to ignore my comment below.

@@ -0,0 +1 @@
No longer require valid typeforms to be callable. This allows :data:`typing.Annotated` to wrap :data:`typing.ParamSpecArgs` and :data:`dataclasses.InitVar`. Patch by Gregory Beauregard.
Copy link
Member

@Fidget-Spinner Fidget-Spinner Mar 10, 2022

Choose a reason for hiding this comment

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

Each line should be under 80 chars. However since this is usually merged into the next release's changelog anyways I'm not sure if it matters.

Copy link
Member

@JelleZijlstra JelleZijlstra Mar 10, 2022

Choose a reason for hiding this comment

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

Yes, I think blurb takes care of that when it generates the full changelog.

@JelleZijlstra JelleZijlstra merged commit 870b22b into python:main Mar 12, 2022
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants