mirror of
https://github.com/astral-sh/ruff
synced 2026-01-09 15:44:22 -05:00
[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
This commit is contained in:
4
.github/workflows/sync_typeshed.yaml
vendored
4
.github/workflows/sync_typeshed.yaml
vendored
@@ -46,6 +46,10 @@ jobs:
|
||||
cp -r typeshed/stdlib ruff/crates/red_knot_vendored/vendor/typeshed/stdlib
|
||||
rm -rf ruff/crates/red_knot_vendored/vendor/typeshed/stdlib/@tests
|
||||
git -C typeshed rev-parse HEAD > ruff/crates/red_knot_vendored/vendor/typeshed/source_commit.txt
|
||||
# Patch the typeshed stubs to include `knot_extensions`
|
||||
ln -s ../../../knot_extensions/knot_extensions.pyi ruff/crates/red_knot_vendored/vendor/typeshed/stdlib/
|
||||
echo "# Patch applied for red_knot:" >> ruff/crates/red_knot_vendored/vendor/typeshed/stdlib/VERSIONS
|
||||
echo "knot_extensions: 3.0-" >> ruff/crates/red_knot_vendored/vendor/typeshed/stdlib/VERSIONS
|
||||
- name: Commit the changes
|
||||
id: commit
|
||||
if: ${{ steps.sync.outcome == 'success' }}
|
||||
|
||||
Reference in New Issue
Block a user