Skip to content

Error inconsistent between type keyword and TypeAlias #20090

@KarelKenens

Description

@KarelKenens

Bug Report
A valid-type error is reported by mypy when using the type keyword for certain expressions, but no error is reported when using TypeAlias.
I can trigger it by using an annotated type, where the annotation is function output, and the annotated type parametrizes another type.
To Reproduce

from typing import Annotated, TypeAlias

def something() -> None: ...

type A= list[Annotated[str, something()]]
B: TypeAlias = list[Annotated[str, something()]]

Expected Behavior

Consistent reporting for type and TypeAlias.

Actual Behavior

main.py:5: error: Invalid type alias: expression is not a valid type  [valid-type]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.18.2
  • Mypy command-line flags: null
  • Mypy configuration options from mypy.ini (and other config files): null
  • Python version used: 3.12, 3.13, 3.14

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-type-aliasTypeAlias and other type alias issues

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions