Files
ruff/crates/ty_python_semantic/resources/lint_docs/experimental-syntax.md
David Peter 1d40d153a9 [ty] Document runtime support in ty-extensions (#30497)
## Summary

The `ty-extensions` package lets Python evaluate and inspect
`Intersection[A, B]` and `Not[A]` at runtime. Update the stub docstrings
and the `experimental-syntax` documentation to point readers to the
package.
2026-11-17 14:41:58 +00:00

1.1 KiB

What it does

Checks for experimental syntax that is not part of the Python typing specification.

Why is this bad?

Experimental syntax is specific to ty. It may be rejected by other type checkers and may never be standardized, or be subject to breaking changes. There are also tools and libraries that inspect and/or evaluate type annotations at runtime, including stringized annotations (e.g. Pydantic, typeguard or beartype). Using experimental syntax may lead to runtime errors in this context.

If you need Python to evaluate these annotations, install ty-extensions and use Intersection[A, B] and Not[A] from ty_extensions instead of A & B and ~A.

Conversely, if you are only using ty as your type checker, and if you are not relying on runtime inspection of type annotations, you can safely ignore this rule.

Examples

[environment]
python-version = "3.14"
class A: ...


class B: ...


def f(value: A & B) -> None: ...  # error: [experimental-syntax]
def g(value: ~A) -> None: ...  # error: [experimental-syntax]