Skip to content

a: Type[T] does not accept parameter of type TypeAliasType #19661

@tybug

Description

@tybug

I encountered this downstream in HypothesisWorks/hypothesis#4410. The core issue there is that it is not the case that TypeAliasType("A", int) < type[int], even though it is the case that NewType("A", int) < type[int]. Is there a reason for the semantics of TypeAliasType and NewType to differ here that I'm missing?

https://mypy-play.net/?mypy=latest&python=3.12&gist=cd7dfca756999eedbb54249461005957

from typing import NewType

def f(a: type[int]):
    pass

A = NewType("A", int)
f(A)  # type checks

type B = int
f(B)  # does not type check

Pyright also behaves similarly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions