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

Appearance settings

typing.Annotated[int, ...] is subclassable #96771

Copy link
Copy link
@sobolevn

Description

@sobolevn
Issue body actions

You can subclass Annotated[int, "meta"]:

>>> import typing
>>> class Some(typing.Annotated[int, 'meta']): ...
... 
>>> Some.__mro__
(<class '__main__.Some'>, <class 'int'>, <class 'object'>)

But, here are a couple of problems:

  1. All metadata is lost: so, no reason to use Annotated in the first place
  2. https://peps.python.org/pep-0593/ never mentions this use-case
  3. We assume that Annotated cannot be subclassed: https://github.com/python/cpython/blame/53a54b781d1f05f2d0b40ce88b3da92d5d23e9d2/Lib/test/test_typing.py#L6562-L6565 here

I think that Annotated should not be subclasses and this is a bug.
The PR is incoming :)

I found this while working on #96769

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.