Skip to content

Fix crash for empty Annotated type application#21503

Merged
ilevkivskyi merged 2 commits into
python:masterfrom
cyphercodes:fix-annotated-empty-21471
May 20, 2026
Merged

Fix crash for empty Annotated type application#21503
ilevkivskyi merged 2 commits into
python:masterfrom
cyphercodes:fix-annotated-empty-21471

Conversation

@cyphercodes
Copy link
Copy Markdown
Contributor

Fixes #21471.

Summary

  • Avoid special-casing Annotated[...] as its inner type when the subscript has no arguments.
  • Let the normal type analyzer report the existing Annotated[...] argument error instead of crashing.
  • Add a regression test for list[Annotated[()]] in type application context.

Tests

  • python3 -m pytest -n0 mypy/test/testcheck.py::TypeCheckSuite::check-annotated.test
  • python3 -m mypy --config-file mypy_self_check.ini -p mypy
  • python3 -m mypy /tmp/mypy21471.py --show-traceback
  • git diff --check

Prepared with AI assistance; I reviewed and verified the changes.

@github-actions
Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Copy Markdown
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

This is fine I think.

@ilevkivskyi ilevkivskyi merged commit 3a969d1 into python:master May 20, 2026
25 checks passed
Sign up for free to 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.

IndexError: list index out of range with missing typing.Annotated type

3 participants