mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:24 +00:00
Default to latest supported Python version for version-related syntax errors (#17529)
## Summary This PR partially addresses #16418 via the following: - `LinterSettings::unresolved_python_version` is now a `TargetVersion`, which is a thin wrapper around an `Option<PythonVersion>` - `Checker::target_version` now calls `TargetVersion::linter_version` internally, which in turn uses `unwrap_or_default` to preserve the current default behavior - Calls to the parser now call `TargetVersion::parser_version`, which calls `unwrap_or_else(PythonVersion::latest)` - The `Checker`'s implementation of `SemanticSyntaxContext::python_version` also uses `TargetVersion::parser_version` to use `PythonVersion::latest` for semantic errors In short, all lint rule behavior should be unchanged, but we default to the latest Python version for the new syntax errors, which should minimize confusing version-related syntax errors for users without a version configured. ## Test Plan Existing tests, which showed no changes (except for printing default settings).
This commit is contained in:
parent
76b6d53d8b
commit
4510a236d3
22 changed files with 139 additions and 71 deletions
|
@ -101,7 +101,8 @@ pub(crate) fn check(
|
|||
settings.linter.unresolved_target_version
|
||||
};
|
||||
|
||||
let parse_options = ParseOptions::from(source_type).with_target_version(target_version);
|
||||
let parse_options =
|
||||
ParseOptions::from(source_type).with_target_version(target_version.parser_version());
|
||||
|
||||
// Parse once.
|
||||
let parsed = ruff_python_parser::parse_unchecked(source_kind.source_code(), parse_options)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue