Skip to content

Simple alias to typing.Annotated is not recognized #1488

@grievejia

Description

@grievejia

Describe the Bug

Minimal repro:

from typing import Annotated

A = Annotated

def test(x: A[int, 0]) -> None:
    pass

Expected: No type error
Actual:

  • Expected a type argument for Annotated
  • type[Annotated] is not subscriptable

In practice people probably won't do this kind of trivial aliasing within the same file. What would happen instead is that they tend to do it in version-compatibility shims, e.g.

# my_library.py
import sys
import typing

if sys.version_info < (3, 9):
  Annotated = SOME_CUSTOM_IMPLEMENTATION_OF_ANNOTATED
else:
  Annotated = typing.Annotated

# my_app.py
from my_library import Annotated
def test(x: Annotated[int, 0]) -> None:
    pass

The pattern is currently (as of 11/14/2025) recognized by both Pyright and Ty, but not Mypy.

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEALqcROgOZ0Q3G6UN0BBdOlwNUDGJgA66GQLoBeQcNHjJMmZhhhG8BgAp8iQQG1WDADR0ADAF0AlHQC0APjoA5XOhiIZdf3TEqHAIFiAArgzQcCTkiFS0jMysHFw8fMqkGuhguLiKmSBhZJTaUKSEDLRQFADEdAAKpKVg5XRoWHj4dADGXpBs4ZTiEF6EMvUAyjAwdAAWDAzEcIgA9KslZRW8bKsw6KuYuD1wq305EIPDUV6rdLmUdKgAbqjQqNiwvf2XQyNedFwxBu6BiMjIDDmXiczxglDgo3QBSkIAAzIQAIwAJhRMhAAF8wqgelFYQAxaAwCgdHAEWIEoA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions