python / python/mypy

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

Open
#21,536 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the reported tstann.py example with mypy --strict and compare the diagnostics for Annotated[int, 'ops'] with the documented Annotated attributes. The payload names no implementation file or existing test; done means the two false-positive attr-defined errors are absent while the relevant behavior remains checked by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.