[ty] Tell the user why we inferred a certain Python version when reporting version-specific syntax errors (#18295)

This commit is contained in:
Alex Waygood 2025-05-26 21:44:43 +01:00 committed by GitHub
parent 0a11baf29c
commit 6453ac9ea1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 201 additions and 107 deletions

View file

@ -23,8 +23,8 @@ use std::sync::Arc;
use thiserror::Error;
use tracing::error;
use ty_python_semantic::lint::{LintRegistry, LintRegistryBuilder, RuleSelection};
use ty_python_semantic::register_lints;
use ty_python_semantic::types::check_types;
use ty_python_semantic::{add_inferred_python_version_hint_to_diagnostic, register_lints};
pub mod combine;
@ -460,12 +460,11 @@ fn check_file_impl(db: &dyn Db, file: File) -> Vec<Diagnostic> {
.map(|error| create_parse_diagnostic(file, error)),
);
diagnostics.extend(
parsed
.unsupported_syntax_errors()
.iter()
.map(|error| create_unsupported_syntax_diagnostic(file, error)),
);
diagnostics.extend(parsed.unsupported_syntax_errors().iter().map(|error| {
let mut error = create_unsupported_syntax_diagnostic(file, error);
add_inferred_python_version_hint_to_diagnostic(db.upcast(), &mut error, "parsing syntax");
error
}));
{
let db = AssertUnwindSafe(db);