Files
ruff/crates/ruff_python_stdlib
Brent Westbrook 652bfea146 Recognize quoted types in typing.TypeForm (#28507)
Summary
--

`typing.TypeForm` was introduced in Python 3.15 and [PEP
747](https://peps.python.org/pep-0747/) as
a way to annotate the passing of type objects like `int | str`,
`list[int]`, or `MyTypeAlias`. It
can be used either as a subscripted generic, as in this example from the
PEP:

```py
from typing import TypeForm

def trycast[T](typx: TypeForm[T], value: object) -> T | None: ...
```

or as a callable, which returns its argument unchanged:

```py
from typing import TypeForm

TypeForm("list[int]")
```

This PR recognizes `typing.TypeForm` as a standard-library generic and
as a known `typing` callable
and visits its argument or subscript as a type definition.

While I was reading the [typing docs], I realized that a couple of
nearby types were also not
listed, so I've attempted to sneak them in here but could split them off
if needed. We already had
coverage for `typing.TypeGuard` but not `typing_extensions.TypeGuard`
(added in 3.10), and we were
missing both variants of `TypeIs` (added in 3.13). These are only valid
in the subscript form, so
they don't need new `Callable` entries.

[typing docs]:
https://docs.python.org/3.15/library/typing.html#typing.TypeForm

Test Plan
--

New mdtests, using `unused-import` (`F401`) to demonstrate that visiting
these arguments as type
definitions marks them as used, but other rules will be affected as
well.
2026-09-11 14:12:38 +00:00
..
2026-09-10 13:47:30 -04:00
2026-09-10 13:47:30 -04:00

ruff_python_stdlib

This crate is an internal component of Ruff. The Rust API exposed here is unstable and will have frequent breaking changes.

This version (0.0.13) is a component of Ruff 0.16.7. The source can be found here.

See Ruff's crate versioning policy for details on versioning.