Skip to content

PyType cannot handle type annotations of TypeAliasType (it's treated as callable) #1775

Open
@wyattscarpenter

Description

TypeAliasType is the type of what you get when you use the type keyword, eg:

type Point = tuple[float, float]

It is valid (or at least mypy and pyright allow you to) to pass the resultant type alias (Point in the example above) to functions, in which case it is supposed to have a type of TypeAliasType, However, annotating a function argument as TypeAliasType produces an error in PyType:

from typing import TypeAliasType

def f (t: TypeAliasType) -> None:
  pass

here is the error:

tat.py:3:1: error: in <module>: Invalid type annotation '<instance of Callable>'  [invalid-annotation]
  Not a type

def f (t: TypeAliasType) -> None:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  pass
~~~~~~

Pyright and mypy don't error on this code, as I've implied.

Possibly related issues:

#1475 (I guess Python 3.12 support is not truly complete until you can do this?)

#1295 (possibly similar decay-to-callable issue?)

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions