ty icon indicating copy to clipboard operation
ty copied to clipboard

Support `type()`'s functional syntax

Open InSyncWithFoo opened this issue 10 months ago • 1 comments

(First raised on Discord.)

Currently ty doesn't understand type()'s functional syntax very well (playground):

# error: Object of type `type` is not assignable to `type[int]`
U32: type[int] = type('U32', (int,), {})

It understands type(...) returns a new type, but fails to take the bases into account.

InSyncWithFoo avatar Jul 01 '25 13:07 InSyncWithFoo

Another example:

from unittest import TestCase

tests: list[type[TestCase]] = []
testCaseClass = type("Foo", (TestCase,), {})

# Argument to bound method `append` is incorrect: Expected `type[TestCase]`, found `type`
tests.append(testCaseClass)

condemil avatar Dec 27 '25 04:12 condemil