Skip to content

"TypeAliasType" not assignable to "TypeForm[Any]" for dict keys, but same expression works inline #11301

@dchevell

Description

@dchevell

This is probably the easiest way to explain it:

from typing import Any
from typing_extensions import TypeForm

mydict: dict[TypeForm[Any], str] = {}

type IntType = type[int]

mydict[IntType] # error: "TypeAliasType" is not assignable to "TypeForm[Any]"
mydict[type[int]] # no error
some_val: TypeForm[Any] = IntType # no error

Example in Pyright Playground

I know TypeForm is still experimental, so this may be expected … or it may simply not be codified when mixing TypeForm rules, dict key invariance rules and type statement TypeAliasTypes. My read from the docs on type statements was that "the value of the type alias is evaluated in the annotation scope" meant TypeAliasTypes should be valid TypeForm objects (which they are, in the some_val case above, but that may be a naive interpretation.

PS: very much appreciate your work on pyright & python typing, thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions