Skip to content

gh-105509: Simplify the implementation of typing.Annotated#105510

Merged
hauntsaninja merged 4 commits intopython:mainfrom
AlexWaygood:refactor-annotated
Sep 1, 2023
Merged

gh-105509: Simplify the implementation of typing.Annotated#105510
hauntsaninja merged 4 commits intopython:mainfrom
AlexWaygood:refactor-annotated

Conversation

@AlexWaygood
Copy link
Copy Markdown
Member

@AlexWaygood AlexWaygood commented Jun 8, 2023

@AlexWaygood AlexWaygood changed the title Simplify the implementation of typing.Annotated gh-105509: Simplify the implementation of typing.Annotated Jun 8, 2023
…IG57j.rst

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Copy link
Copy Markdown
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Quick note: right now it is possible to use Annotated in isinstance(1, typing.Annotated). However, it does not make much sense anyway:

>>> isinstance(typing.Annotated[int, 1], typing.Annotated)
False

With this patch applied it will raise a TypeError.

I don't think that it is a big deal.

@AlexWaygood
Copy link
Copy Markdown
Member Author

AlexWaygood commented Jun 8, 2023

Yeah. You can think up ways that this could break people's code, if they're doing strange things with typing at runtime (and as such, I definitely don't think it should be backported). But I don't think we're changing anything about the public API for this symbol here, so nothing about the contract is being broken.

Copy link
Copy Markdown
Contributor

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Looks good to me! Couldn't find any isinstance(..., Annotated) in a quick search

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.

Simplify the implementation of typing.Annotated

5 participants