Latest Results
[ty] Support `typing.TypeForm` (#25334)
## Summary
`TypeForm[T]` describes a value that is a valid type expression
representing a type assignable to `T`. Unlike `type[T]`, it can describe
forms such as parameterized generics and unions, not only runtime class
objects:
```python
from typing import assert_type
from typing_extensions import TypeForm
def construct[T](form: TypeForm[T]) -> T:
raise NotImplementedError
assert_type(construct(int), int)
assert_type(construct(list[int]), list[int])
assert_type(construct(int | str), int | str)
```
This PR adds support for `TypeForm[T]`, bringing us into alignment with
the conformance suite.
For bare `type`, we treat it as a runtime class value, but one that
doesn't promise a specific represented type, so it's valid for broad
TypeForm destinations, but not narrow ones:
```python
def use_bare_runtime_class(runtime_type: type) -> None:
any_form: TypeForm[Any] = runtime_type
object_form: TypeForm[object] = runtime_type
string_form: TypeForm[str] = runtime_type # error
```
Closes https://github.com/astral-sh/ty/issues/2668. [ty] Infer class attributes assigned by metaclass initialization (#25342)
## Summary
Prior to this change, we didn't recognize class-object attributes
populated by a metaclass during class initialization. For example:
```python
class Meta(type):
def __init__(cls, name: str, bases: tuple[type, ...], namespace: dict[str, object]) -> None:
cls.attr: int = 1
class C(metaclass=Meta): ...
reveal_type(C.attr) # revealed: int
```
We now recognize attributes that a metaclass adds to a class while
creating it. If the metaclass overwrites an existing class-body value,
we use the overwritten value's type. If the class provides an annotation
for the generated attribute, we preserve that annotation as its public
type.
For example, if the class body initially gives attr a value, the
metaclass assignment happens later at runtime and overwrites it:
```python
class Meta(type):
def __init__(cls, name, bases, namespace):
cls.attr: int = 1
class C(metaclass=Meta):
attr = "initial value"
reveal_type(C.attr) # int
```
Closes https://github.com/astral-sh/ty/issues/1138. Latest Branches
0%
0%
charlie/codex-metaclass-init-class-attributes -7%
© 2026 CodSpeed Technology