Files
ruff/crates/ty_python_semantic/resources/mdtest/annotations/generic_alias.md
David Peter 116fd7c7af [ty] Remove GenericAlias-related todo type (#21728)
## Summary

If you manage to create an `typing.GenericAlias` instance without us
knowing how that was created, then we don't know what to do with this in
a type annotation. So it's better to be explicit and show an error
instead of failing silently with a `@Todo` type.

## Test Plan

* New Markdown tests
* Zero ecosystem impact
2025-12-01 13:02:38 +00:00

1021 B

GenericAlias in type expressions

We recognize if a types.GenericAlias instance is created by specializing a generic class. We don't explicitly mention it in our type display, but list[int] in the example below is a GenericAlias instance at runtime:

Numbers = list[int]

# At runtime, `Numbers` is an instance of `types.GenericAlias`. Showing
# this as `list[int]` is more helpful, though:
reveal_type(Numbers)  # revealed: <class 'list[int]'>

def _(numbers: Numbers) -> None:
    reveal_type(numbers)  # revealed: list[int]

It is also valid to create GenericAlias instances manually:

from types import GenericAlias

Strings = GenericAlias(list, (str,))

reveal_type(Strings)  # revealed: GenericAlias

However, using such a GenericAlias instance in a type expression is currently not supported:

# error: [invalid-type-form] "Variable of type `GenericAlias` is not allowed in a type expression"
def _(strings: Strings) -> None:
    reveal_type(strings)  # revealed: Unknown