Skip to content

Commit 06f9f52

Browse files
authored
[ty] Add support for @warnings.deprecated (astral-sh#19376)
* [x] basic handling * [x] parse and discover `@warnings.deprecated` attributes * [x] associate them with function definitions * [x] associate them with class definitions * [x] add a new "deprecated" diagnostic * [x] ensure diagnostic is styled appropriately for LSPs (DiagnosticTag::Deprecated) * [x] functions * [x] fire on calls * [x] fire on arbitrary references * [x] classes * [x] fire on initializers * [x] fire on arbitrary references * [x] methods * [x] fire on calls * [x] fire on arbitrary references * [ ] overloads * [ ] fire on calls * [ ] fire on arbitrary references(??? maybe not ???) * [ ] only fire if the actual selected overload is deprecated * [ ] dunder desugarring (warn on deprecated `__add__` if `+` is invoked) * [ ] alias supression? (don't warn on uses of variables that deprecated items were assigned to) * [ ] import logic * [x] fire on imports of deprecated items * [ ] suppress subsequent diagnostics if the import diagnostic fired (is this handled by alias supression?) * [x] fire on all qualified references (`module.mydeprecated`) * [x] fire on all references that depend on a `*` import Fixes astral-sh/ty#153
1 parent e9a64e5 commit 06f9f52

File tree

15 files changed

+1000
-73
lines changed

15 files changed

+1000
-73
lines changed

crates/ruff_benchmark/benches/ty.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -527,14 +527,21 @@ impl<'a> ProjectBenchmark<'a> {
527527

528528
#[track_caller]
529529
fn bench_project(benchmark: &ProjectBenchmark, criterion: &mut Criterion) {
530-
fn check_project(db: &mut ProjectDatabase, max_diagnostics: usize) {
530+
fn check_project(db: &mut ProjectDatabase, project_name: &str, max_diagnostics: usize) {
531531
let result = db.check();
532532
let diagnostics = result.len();
533533

534-
assert!(
535-
diagnostics <= max_diagnostics,
536-
"Expected <={max_diagnostics} diagnostics but got {diagnostics}"
537-
);
534+
if diagnostics > max_diagnostics {
535+
let details = result
536+
.into_iter()
537+
.map(|diagnostic| diagnostic.concise_message().to_string())
538+
.collect::<Vec<_>>()
539+
.join("\n ");
540+
assert!(
541+
diagnostics <= max_diagnostics,
542+
"{project_name}: Expected <={max_diagnostics} diagnostics but got {diagnostics}:\n {details}",
543+
);
544+
}
538545
}
539546

540547
setup_rayon();
@@ -544,7 +551,7 @@ fn bench_project(benchmark: &ProjectBenchmark, criterion: &mut Criterion) {
544551
group.bench_function(benchmark.project.config.name, |b| {
545552
b.iter_batched_ref(
546553
|| benchmark.setup_iteration(),
547-
|db| check_project(db, benchmark.max_diagnostics),
554+
|db| check_project(db, benchmark.project.config.name, benchmark.max_diagnostics),
548555
BatchSize::SmallInput,
549556
);
550557
});
@@ -612,7 +619,7 @@ fn datetype(criterion: &mut Criterion) {
612619
max_dep_date: "2025-07-04",
613620
python_version: PythonVersion::PY313,
614621
},
615-
0,
622+
2,
616623
);
617624

618625
bench_project(&benchmark, criterion);

crates/ty/docs/rules.md

Lines changed: 83 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)