ruff/crates/ruff_linter/src/rules/flake8_bugbear
Brent Westbrook 4510a236d3
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).
2025-05-06 10:19:13 -04:00
..
rules Use #[expect(lint)] over #[allow(lint)] where possible (#17822) 2025-05-03 21:20:31 +02:00
snapshots [flake8-bugbear] Exempt NewType calls where the original type is immutable (B008) (#15765) 2025-01-29 10:26:17 +00:00
helpers.rs Extract LineIndex independent methods from Locator (#13938) 2024-10-28 07:53:41 +00:00
mod.rs Default to latest supported Python version for version-related syntax errors (#17529) 2025-05-06 10:19:13 -04:00
settings.rs ruff server now supports the source.organizeImports source action (#10652) 2024-04-04 22:20:50 +00:00