Skip to content

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

Merged
JelleZijlstra merged 9 commits into
python:mainfrom
GBeauregard:remove-type-check-callable
Mar 12, 2022
Merged

bpo-46644: Remove callable() requirement from typing._type_check#31151
JelleZijlstra merged 9 commits into
python:mainfrom
GBeauregard:remove-type-check-callable

Conversation

@GBeauregard

@GBeauregardGBeauregard commented Feb 5, 2022

Copy link
Copy Markdown
Contributor

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 February 5, 2022 22:10
@GBeauregardGBeauregard changed the title bpo-46644: Remove type check callablebpo-46644: Remove callable() requirement from typing._type_checkFeb 5, 2022
Comment threadLib/test/test_types.py
Comment threadLib/test/test_typing.py
Comment threadMisc/NEWS.d/next/Library/2022-02-05-22-14-44.bpo-46644.P--1Cz.rst Outdated
@gvanrossum

Copy link
Copy Markdown
Member

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

@JelleZijlstraJelleZijlstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@gvanrossumgvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, that’s fair. Godspeed!

@JelleZijlstraJelleZijlstra self-assigned this Mar 10, 2022

@Fidget-SpinnerFidget-Spinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
Copy Markdown
Member

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
Copy Markdown
Member

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:mainMar 12, 2022
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@GBeauregard@gvanrossum@JelleZijlstra@Fidget-Spinner@the-knights-who-say-ni@bedevere-bot