ruff/crates/red_knot_python_semantic/src/semantic_index
David Peter 235fdfc57a
[red-knot] knot_extensions Python API (#15103)
## Summary

Adds a type-check-time Python API that allows us to create and
manipulate types and to test various of their properties. For example,
this can be used to write a Markdown test to make sure that `A & B` is a
subtype of `A` and `B`, but not of an unrelated class `C` (something
that requires quite a bit more code to do in Rust):
```py
from knot_extensions import Intersection, is_subtype_of, static_assert

class A: ...
class B: ...

type AB = Intersection[A, B]

static_assert(is_subtype_of(AB, A))
static_assert(is_subtype_of(AB, B))

class C: ...
static_assert(not is_subtype_of(AB, C))
```

I think this functionality is also helpful for interactive debugging
sessions, in order to query various properties of Red Knot's type
system. Which is something that otherwise requires a custom Rust unit
test, some boilerplate code and constant re-compilation.

## Test Plan

- New Markdown tests
- Tested the modified typeshed_sync workflow locally
2025-01-08 12:52:07 +01:00
..
builder [red-knot] Add control flow for try/except blocks (#13729) 2024-10-16 13:03:59 +00:00
use_def [red-knot] Statically known branches (#15019) 2024-12-21 11:33:10 +01:00
ast_ids.rs [red-knot] Simplify some traits in ast_ids.rs (#14379) 2024-11-16 17:22:23 +00:00
builder.rs Narrowing for class patterns in match statements (#15223) 2025-01-07 15:58:12 -05:00
constraint.rs Narrowing for class patterns in match statements (#15223) 2025-01-07 15:58:12 -05:00
definition.rs [red-knot] knot_extensions Python API (#15103) 2025-01-08 12:52:07 +01:00
expression.rs Remove AST-node dependency from FunctionType and ClassType (#14087) 2024-11-05 08:02:38 +00:00
symbol.rs @no_type_check support (#15122) 2024-12-30 09:42:18 +00:00
use_def.rs [red-knot] Statically known branches (#15019) 2024-12-21 11:33:10 +01:00