diff --git a/crates/ruff_benchmark/benches/ty.rs b/crates/ruff_benchmark/benches/ty.rs index 02a10a4100..f1000fb050 100644 --- a/crates/ruff_benchmark/benches/ty.rs +++ b/crates/ruff_benchmark/benches/ty.rs @@ -450,9 +450,6 @@ fn benchmark_complex_constrained_attributes_2(criterion: &mut Criterion) { r#" class C: def f(self: "C"): - self.a = "" - self.b = "" - if isinstance(self.a, str): return @@ -466,6 +463,56 @@ fn benchmark_complex_constrained_attributes_2(criterion: &mut Criterion) { return if isinstance(self.b, str): return + if isinstance(self.b, str): + return + if isinstance(self.b, str): + return + + self.a = "" + self.b = "" + "#, + ) + }, + |case| { + let Case { db, .. } = case; + let result = db.check(); + assert_eq!(result.len(), 0); + }, + BatchSize::SmallInput, + ); + }); +} + +fn benchmark_complex_constrained_attributes_3(criterion: &mut Criterion) { + setup_rayon(); + + criterion.bench_function("ty_micro[complex_constrained_attributes_3]", |b| { + b.iter_batched_ref( + || { + // This is a regression test for https://github.com/astral-sh/ty/issues/758 + setup_micro_case( + r#" + class GridOut: + def __init__(self: "GridOut") -> None: + self._buffer = b"" + + def _read_size_or_line(self: "GridOut", size: int = -1): + if size > self._position: + size = self._position + pass + if size == 0: + return bytes() + + while size > 0: + if self._buffer: + buf = self._buffer + self._buffer = b"" + else: + buf = b"" + + if len(buf) > size: + self._buffer = buf + self._position -= len(self._buffer) "#, ) }, @@ -668,6 +715,7 @@ criterion_group!( benchmark_tuple_implicit_instance_attributes, benchmark_complex_constrained_attributes_1, benchmark_complex_constrained_attributes_2, + benchmark_complex_constrained_attributes_3, benchmark_many_enum_members, ); criterion_group!(project, anyio, attrs, hydra, datetype);