Skip to content

Commit 4460bd1

Browse files
committed
Merge branch 'main' into dcreager/unpack-tuple
* main: [ty] Add regression-benchmark for attribute-assignment hang (#18957) [ty] Format conflicting types as an enumeration (#18956) [ty] Prevent union builder construction for just one declaration (#18954) [ty] Infer nonlocal types as unions of all reachable bindings (#18750) [`pyflakes`] Mark `F504`/`F522`/`F523` autofix as unsafe if there's a call with side effect (#18839) [`playground`] Add ruff logo docs link to Header.tsx (#18947) [ty] Reduce the overwhelming complexity of `TypeInferenceBuilder::infer_call_expression` (#18943) [ty] Add subdiagnostic about empty bodies in more cases (#18942) [ty] Move search path resolution to `Options::to_program_settings` (#18937) [`flake8-errmsg`] Extend `EM101` to support byte strings (#18867) Move big rule implementations (#18931) [`pylint`] Allow fix with comments and document performance implications (`PLW3301`) (#18936)
2 parents de6baf8 + d04e63a commit 4460bd1

File tree

75 files changed

+2850
-1754
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2850
-1754
lines changed

crates/ruff/tests/analyze_graph.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,9 @@ fn venv() -> Result<()> {
566566
----- stderr -----
567567
ruff failed
568568
Cause: Invalid search path settings
569-
Cause: Failed to discover the site-packages directory: Invalid `--python` argument `none`: does not point to a Python executable or a directory on disk
569+
Cause: Failed to discover the site-packages directory
570+
Cause: Invalid `--python` argument `none`: does not point to a Python executable or a directory on disk
571+
Cause: No such file or directory (os error 2)
570572
");
571573
});
572574

crates/ruff_benchmark/benches/ty.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,58 @@ fn benchmark_many_tuple_assignments(criterion: &mut Criterion) {
348348
});
349349
}
350350

351+
fn benchmark_many_attribute_assignments(criterion: &mut Criterion) {
352+
setup_rayon();
353+
354+
criterion.bench_function("ty_micro[many_attribute_assignments]", |b| {
355+
b.iter_batched_ref(
356+
|| {
357+
// This is a regression benchmark for https://github.com/astral-sh/ty/issues/627.
358+
// Before this was fixed, the following sample would take >1s to type check.
359+
setup_micro_case(
360+
r#"
361+
class C:
362+
def f(self: "C"):
363+
if isinstance(self.a, str):
364+
return
365+
366+
if isinstance(self.b, str):
367+
return
368+
if isinstance(self.b, str):
369+
return
370+
if isinstance(self.b, str):
371+
return
372+
if isinstance(self.b, str):
373+
return
374+
if isinstance(self.b, str):
375+
return
376+
if isinstance(self.b, str):
377+
return
378+
if isinstance(self.b, str):
379+
return
380+
if isinstance(self.b, str):
381+
return
382+
if isinstance(self.b, str):
383+
return
384+
if isinstance(self.b, str):
385+
return
386+
if isinstance(self.b, str):
387+
return
388+
if isinstance(self.b, str):
389+
return
390+
"#,
391+
)
392+
},
393+
|case| {
394+
let Case { db, .. } = case;
395+
let result = db.check();
396+
assert!(!result.is_empty());
397+
},
398+
BatchSize::SmallInput,
399+
);
400+
});
401+
}
402+
351403
struct ProjectBenchmark<'a> {
352404
project: InstalledProject<'a>,
353405
fs: MemoryFileSystem,
@@ -483,6 +535,7 @@ criterion_group!(
483535
micro,
484536
benchmark_many_string_assignments,
485537
benchmark_many_tuple_assignments,
538+
benchmark_many_attribute_assignments,
486539
);
487540
criterion_group!(project, anyio, attrs, hydra);
488541
criterion_main!(check_file, micro, project);

crates/ruff_graph/src/db.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::Result;
1+
use anyhow::{Context, Result};
22
use std::sync::Arc;
33
use zip::CompressionMethod;
44

@@ -42,17 +42,21 @@ impl ModuleDb {
4242
}
4343

4444
let db = Self::default();
45+
let search_paths = search_paths
46+
.to_search_paths(db.system(), db.vendored())
47+
.context("Invalid search path settings")?;
48+
4549
Program::from_settings(
4650
&db,
4751
ProgramSettings {
48-
python_version: Some(PythonVersionWithSource {
52+
python_version: PythonVersionWithSource {
4953
version: python_version,
5054
source: PythonVersionSource::default(),
51-
}),
55+
},
5256
python_platform: PythonPlatform::default(),
5357
search_paths,
5458
},
55-
)?;
59+
);
5660

5761
Ok(db)
5862
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def f_byte():
2+
raise RuntimeError(b"This is an example exception")
3+
4+
5+
def f_byte_empty():
6+
raise RuntimeError(b"")

crates/ruff_linter/resources/test/fixtures/pyflakes/F504.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@
1414
"" % {
1515
'test1': '', 'test2': '',
1616
}
17+
18+
# https://github.com/astral-sh/ruff/issues/18806
19+
"Hello, %(name)s" % {"greeting": print(1), "name": "World"}

crates/ruff_linter/resources/test/fixtures/pyflakes/F522.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,11 @@
44
"{bar:{spam}}".format(bar=2, spam=3, eggs=4, ham=5) # F522
55
(''
66
.format(x=2)) # F522
7+
8+
# https://github.com/astral-sh/ruff/issues/18806
9+
# The fix here is unsafe because the unused argument has side effect
10+
"Hello, {name}".format(greeting=print(1), name="World")
11+
12+
# The fix here is safe because the unused argument has no side effect,
13+
# even though the used argument has a side effect
14+
"Hello, {name}".format(greeting="Pikachu", name=print(1))

crates/ruff_linter/resources/test/fixtures/pyflakes/F523.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,11 @@
3535
# Removing the final argument.
3636
"Hello".format("world")
3737
"Hello".format("world", key="value")
38+
39+
# https://github.com/astral-sh/ruff/issues/18806
40+
# The fix here is unsafe because the unused argument has side effect
41+
"Hello, {0}".format("world", print(1))
42+
43+
# The fix here is safe because the unused argument has no side effect,
44+
# even though the used argument has a side effect
45+
"Hello, {0}".format(print(1), "Pikachu")

crates/ruff_linter/resources/test/fixtures/pylint/nested_min_max.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# This will still trigger, to merge the calls without keyword args.
1515
min(1, min(2, 3, key=test), min(4, 5))
1616

17-
# Don't provide a fix if there are comments within the call.
17+
# The fix is already unsafe, so deleting comments is okay.
1818
min(
1919
1, # This is a comment.
2020
min(2, 3),

0 commit comments

Comments
 (0)