ruff/crates/red_knot_python_semantic/resources/mdtest/import
Brent Westbrook 9c47b6dbb0
[red-knot] Detect version-related syntax errors (#16379)
## Summary
This PR extends version-related syntax error detection to red-knot. The
main changes here are:

1. Passing `ParseOptions` specifying a `PythonVersion` to parser calls
2. Adding a `python_version` method to the `Db` trait to make this
possible
3. Converting `UnsupportedSyntaxError`s to `Diagnostic`s
4. Updating existing mdtests  to avoid unrelated syntax errors

My initial draft of (1) and (2) in #16090 instead tried passing a
`PythonVersion` down to every parser call, but @MichaReiser suggested
the `Db` approach instead
[here](https://github.com/astral-sh/ruff/pull/16090#discussion_r1969198407),
and I think it turned out much nicer.

All of the new `python_version` methods look like this:

```rust
fn python_version(&self) -> ruff_python_ast::PythonVersion {
    Program::get(self).python_version(self)
}
```

with the exception of the `TestDb` in `ruff_db`, which hard-codes
`PythonVersion::latest()`.

## Test Plan

Existing mdtests, plus a new mdtest to see at least one of the new
diagnostics.
2025-04-17 14:00:30 -04:00
..
basic.md [red-knot] Case sensitive module resolver (#16521) 2025-03-14 19:16:44 +00:00
builtins.md [red-knot] improve function/bound method type display (#17294) 2025-04-14 15:56:18 -07:00
case_sensitive.md [red-knot] Case sensitive module resolver (#16521) 2025-03-14 19:16:44 +00:00
conditional.md [red-knot] improve function/bound method type display (#17294) 2025-04-14 15:56:18 -07:00
conflicts.md [red-knot] Enforce specifying paths for mdtest code blocks in a separate preceding line (#15890) 2025-02-04 08:27:17 +01:00
conventions.md Use python.typing.org for typing documentation links (#17323) 2025-04-09 20:38:20 +02:00
errors.md [red-knot] Enforce specifying paths for mdtest code blocks in a separate preceding line (#15890) 2025-02-04 08:27:17 +01:00
invalid_syntax.md [red-knot] Enforce specifying paths for mdtest code blocks in a separate preceding line (#15890) 2025-02-04 08:27:17 +01:00
relative.md [red-knot] Fix python setting in mdtests, and rewrite a site-packages test as an mdtest (#17222) 2025-04-06 18:24:32 +01:00
star.md [red-knot] Detect version-related syntax errors (#16379) 2025-04-17 14:00:30 -04:00
stub_packages.md [red-knot] Support stub packages (#17204) 2025-04-07 14:40:50 +02:00
stubs.md [red-knot] Enforce specifying paths for mdtest code blocks in a separate preceding line (#15890) 2025-02-04 08:27:17 +01:00
tracking.md [red-knot] Enforce specifying paths for mdtest code blocks in a separate preceding line (#15890) 2025-02-04 08:27:17 +01:00