Skip to content

Support type annotations that use legacy typing aliases for generic classes #548

@AlexWaygood

Description

@AlexWaygood

ty currently only has partial support for legacy aliases such as Dict, List, FrozenSet, etc. For example, these two reveal_type calls should both reveal dict[str, int], but the second one does not:

from typing import Dict

def f(x: dict[str, int], y: Dict[str, int]):
    reveal_type(x)  # revealed: dict[str, int]
    reveal_type(y)  # revealed: dict[Unknown, Unknown]

We now support generics, so this should be fairly easy to fix. We need to resolve the TODOs in this area of the code: https://github.com/astral-sh/ruff/blob/ad2f667ee4323dd0c12224338734d722d13d28b4/crates/ty_python_semantic/src/types/infer.rs#L8753-L8789

Metadata

Metadata

Assignees

Labels

genericsBugs or features relating to ty's generics implementationhelp wantedContributions especially welcome

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions