mirror of
				https://github.com/astral-sh/ruff.git
				synced 2025-10-31 03:55:09 +00:00 
			
		
		
		
	[ty] Benchmarks for problematic implicit instance attributes cases (#20133)
## Summary Add regression benchmarks for the problematic cases in https://github.com/astral-sh/ty/issues/758. I'd like to merge this before https://github.com/astral-sh/ruff/pull/20128 to measure the impact (local tests show that this will "solve" both cases).
This commit is contained in:
		
							parent
							
								
									76a6b7e3e2
								
							
						
					
					
						commit
						e586f6dcc4
					
				
					 1 changed files with 51 additions and 3 deletions
				
			
		|  | @ -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); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 David Peter
						David Peter