Skip to content

[False positive] "type[...]" has no attribute "__metadata__" (and __origin__) #21536

@AndrewUshakov

Description

@AndrewUshakov

Bug Report

Please consider the working script below:

from typing import Annotated

T = Annotated[int, 'ops']


if __name__ == '__main__':
    print(T.__origin__)
    # ^^^^^^^^^^^^^^^^^^^----- error: "type[int]" has no attribute "__origin__"  [attr-defined]
    print(T.__metadata__)
    # ^^^^^^^^^^^^^^^^^^^----- error: "type[int]" has no attribute "__metadata__"  [attr-defined]

where mypy generates 2 errors.

(.venv314) PS C:\Users\XXXXXX\YYYYY> mypy --strict tstann.py
tstann.py:7: error: "type[int]" has no attribute "__origin__"  [attr-defined]
tstann.py:9: error: "type[int]" has no attribute "__metadata__"  [attr-defined]
Found 2 errors in 1 file (checked 1 source file)

Expected Behavior

Absence of these errors

Your Environment

  • Mypy version used: 2.1.0 from pypi
  • Mypy command-line flags: --strict
  • Mypy configuration options from mypy.ini (and other config files): absent
  • Python version used: 3.14.5
  • Windows 11

Additionally

These attributes are documented in https://docs.python.org/3/library/typing.html#typing.Annotated

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong
    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