Skip to content

TypeAliasType in runtime expression should evaluate to type TypeAliasType rather than type[TypeAliasType] #7109

@tobias-haenel

Description

@tobias-haenel

Describe the bug
A type that was defined with the new Python 3.12 type A = B syntax, produces a wrong return type from a generic function, when the return type is defined from a type alias object.

Code or Screenshots

from typing import Any
import numpy as np

type F64Arr2D = np.ndarray[tuple[int, int], np.dtype[np.float64]]


def check_type[T](t: type[T], obj: Any) -> T:
    # custom runtime type checking
    return obj


a = check_type(F64Arr2D, np.array([[2.5, 3.5], [1.5, 1.0]]))
reveal_type(a)  # Type of "a" is "TypeAliasType"

Expected behaviour
Type of a should be inferred as ndarray[tuple[int, int], dtype[floating[_64Bit]]

VS Code extension or command-line
Running pyright 1.1.348 as a language server with neovim 0.9.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    addressed in next versionIssue is fixed and will appear in next published versionbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions