Skip to content

Commit a5b2827

Browse files
committed
Merge remote-tracking branch 'origin/main' into dcreager/specialize-deep-dish
* origin/main: [ty] Infer parameter specializations of generic aliases (#18021) [ty] Understand homogeneous tuple annotations (#17998) [ty] Induct into instances and subclasses when finding and applying generics (#18052) [ty] Allow classes to inherit from `type[Any]` or `type[Unknown]` (#18060) [ty] Allow a class to inherit from an intersection if the intersection contains a dynamic type and the intersection is not disjoint from `type` (#18055) [ty] Narrowing for `hasattr()` (#18053) Update reference documentation for `--python-version` (#18056) [`flake8-bugbear`] Ignore `B028` if `skip_file_prefixes` is present (#18047) [`airflow`] Apply try-catch guard to all AIR3 rules (`AIR3`) (#17887) [`pylint`] add fix safety section (`PLW3301`) (#17878) Update `--python` to accept paths to executables in virtual environments (#17954) [`pylint`] add fix safety section (`PLE4703`) (#17824) [`ruff`] Implement a recursive check for `RUF060` (#17976) [`flake8-use-pathlib`] `PTH*` suppress diagnostic for all `os.*` functions that have the `dir_fd` parameter (#17968) [`refurb`] Mark autofix as safe only for number literals in `FURB116` (#17692) [`flake8-simplify`] Fix `SIM905` autofix for `rsplit` creating a reversed list literal (#18045) Avoid initializing progress bars early (#18049)
2 parents 0837d74 + 0fb94c0 commit a5b2827

File tree

74 files changed

+1765
-494
lines changed

Some content is hidden

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

74 files changed

+1765
-494
lines changed

crates/ruff_benchmark/benches/ty.rs

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use ruff_python_ast::PythonVersion;
1616
use ty_project::metadata::options::{EnvironmentOptions, Options};
1717
use ty_project::metadata::value::RangedValue;
1818
use ty_project::watch::{ChangeEvent, ChangedKind};
19-
use ty_project::{Db, DummyReporter, ProjectDatabase, ProjectMetadata};
19+
use ty_project::{Db, ProjectDatabase, ProjectMetadata};
2020

2121
struct Case {
2222
db: ProjectDatabase,
@@ -59,40 +59,7 @@ type KeyDiagnosticFields = (
5959
Severity,
6060
);
6161

62-
// left: [
63-
// (Lint(LintName("invalid-argument-type")), Some("/src/tomllib/_parser.py"), Some(8224..8254), "Argument to function `skip_until` is incorrect", Error),
64-
// (Lint(LintName("invalid-argument-type")), Some("/src/tomllib/_parser.py"), Some(16914..16948), "Argument to function `skip_until` is incorrect", Error),
65-
// (Lint(LintName("invalid-argument-type")), Some("/src/tomllib/_parser.py"), Some(17319..17363), "Argument to function `skip_until` is incorrect", Error),
66-
// ]
67-
//right: [
68-
// (Lint(LintName("invalid-argument-type")), Some("/src/tomllib/_parser.py"), Some(8224..8254), "Argument to this function is incorrect", Error),
69-
// (Lint(LintName("invalid-argument-type")), Some("/src/tomllib/_parser.py"), Some(16914..16948), "Argument to this function is incorrect", Error),
70-
// (Lint(LintName("invalid-argument-type")), Some("/src/tomllib/_parser.py"), Some(17319..17363), "Argument to this function is incorrect", Error),
71-
// ]
72-
73-
static EXPECTED_TOMLLIB_DIAGNOSTICS: &[KeyDiagnosticFields] = &[
74-
(
75-
DiagnosticId::lint("invalid-argument-type"),
76-
Some("/src/tomllib/_parser.py"),
77-
Some(8224..8254),
78-
"Argument to function `skip_until` is incorrect",
79-
Severity::Error,
80-
),
81-
(
82-
DiagnosticId::lint("invalid-argument-type"),
83-
Some("/src/tomllib/_parser.py"),
84-
Some(16914..16948),
85-
"Argument to function `skip_until` is incorrect",
86-
Severity::Error,
87-
),
88-
(
89-
DiagnosticId::lint("invalid-argument-type"),
90-
Some("/src/tomllib/_parser.py"),
91-
Some(17319..17363),
92-
"Argument to function `skip_until` is incorrect",
93-
Severity::Error,
94-
),
95-
];
62+
static EXPECTED_TOMLLIB_DIAGNOSTICS: &[KeyDiagnosticFields] = &[];
9663

9764
fn tomllib_path(file: &TestFile) -> SystemPathBuf {
9865
SystemPathBuf::from("src").join(file.name())
@@ -164,7 +131,7 @@ fn benchmark_incremental(criterion: &mut Criterion) {
164131
fn setup() -> Case {
165132
let case = setup_tomllib_case();
166133

167-
let result: Vec<_> = case.db.check(&DummyReporter).unwrap();
134+
let result: Vec<_> = case.db.check().unwrap();
168135

169136
assert_diagnostics(&case.db, &result, EXPECTED_TOMLLIB_DIAGNOSTICS);
170137

@@ -192,7 +159,7 @@ fn benchmark_incremental(criterion: &mut Criterion) {
192159
None,
193160
);
194161

195-
let result = db.check(&DummyReporter).unwrap();
162+
let result = db.check().unwrap();
196163

197164
assert_eq!(result.len(), EXPECTED_TOMLLIB_DIAGNOSTICS.len());
198165
}
@@ -212,7 +179,7 @@ fn benchmark_cold(criterion: &mut Criterion) {
212179
setup_tomllib_case,
213180
|case| {
214181
let Case { db, .. } = case;
215-
let result: Vec<_> = db.check(&DummyReporter).unwrap();
182+
let result: Vec<_> = db.check().unwrap();
216183

217184
assert_diagnostics(db, &result, EXPECTED_TOMLLIB_DIAGNOSTICS);
218185
},
@@ -326,7 +293,7 @@ fn benchmark_many_string_assignments(criterion: &mut Criterion) {
326293
},
327294
|case| {
328295
let Case { db, .. } = case;
329-
let result = db.check(&DummyReporter).unwrap();
296+
let result = db.check().unwrap();
330297
assert_eq!(result.len(), 0);
331298
},
332299
BatchSize::SmallInput,
Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
from __future__ import annotations
22

33
try:
4-
from airflow.sdk import Asset
4+
from airflow.assets.manager import AssetManager
55
except ModuleNotFoundError:
6-
from airflow.datasets import Dataset as Asset
6+
from airflow.datasets.manager import DatasetManager as AssetManager
77

8-
Asset
9-
10-
try:
11-
from airflow.sdk import Asset
12-
except ModuleNotFoundError:
13-
from airflow import datasets
14-
15-
Asset = datasets.Dataset
16-
17-
asset = Asset()
8+
AssetManager()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from __future__ import annotations
2+
3+
try:
4+
from airflow.providers.http.operators.http import HttpOperator
5+
except ModuleNotFoundError:
6+
from airflow.operators.http_operator import SimpleHttpOperator as HttpOperator
7+
8+
HttpOperator()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from __future__ import annotations
2+
3+
try:
4+
from airflow.sdk import Asset
5+
except ModuleNotFoundError:
6+
from airflow.datasets import Dataset as Asset
7+
8+
Asset()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from __future__ import annotations
2+
3+
try:
4+
from airflow.providers.standard.triggers.file import FileTrigger
5+
except ModuleNotFoundError:
6+
from airflow.triggers.file import FileTrigger
7+
8+
FileTrigger()

crates/ruff_linter/resources/test/fixtures/flake8_bugbear/B028.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,11 @@
2525
# some comments here
2626
source = None # no trailing comma
2727
)
28+
29+
# https://github.com/astral-sh/ruff/issues/18011
30+
warnings.warn("test", skip_file_prefixes=(os.path.dirname(__file__),))
31+
# trigger diagnostic if `skip_file_prefixes` is present and set to the default value
32+
warnings.warn("test", skip_file_prefixes=())
33+
34+
_my_prefixes = ("this","that")
35+
warnings.warn("test", skip_file_prefixes = _my_prefixes)

crates/ruff_linter/resources/test/fixtures/flake8_simplify/SIM905.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
" a*a a*a a ".split("*", -1) # [" a", "a a", "a a "]
3333
"".split() # []
34-
"""
34+
"""
3535
""".split() # []
3636
" ".split() # []
3737
"/abc/".split() # ["/abc/"]
@@ -73,7 +73,7 @@
7373

7474
# negatives
7575

76-
# invalid values should not cause panic
76+
# invalid values should not cause panic
7777
"a,b,c,d".split(maxsplit="hello")
7878
"a,b,c,d".split(maxsplit=-"hello")
7979

@@ -106,3 +106,7 @@
106106
'''itemC'''
107107
"'itemD'"
108108
""".split()
109+
110+
# https://github.com/astral-sh/ruff/issues/18042
111+
print("a,b".rsplit(","))
112+
print("a,b,c".rsplit(",", 1))

crates/ruff_linter/resources/test/fixtures/flake8_use_pathlib/PTH207.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@
99
glob.glob(os.path.join(extensions_dir, "ops", "autograd", "*.cpp"))
1010
list(glob.iglob(os.path.join(extensions_dir, "ops", "autograd", "*.cpp")))
1111
search("*.png")
12+
13+
# if `dir_fd` is set, suppress the diagnostic
14+
glob.glob(os.path.join(extensions_dir, "ops", "autograd", "*.cpp"), dir_fd=1)
15+
list(glob.iglob(os.path.join(extensions_dir, "ops", "autograd", "*.cpp"), dir_fd=1))

crates/ruff_linter/resources/test/fixtures/flake8_use_pathlib/full_name.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,20 @@ def bar(x: int):
8787
os.rename("src", "dst", src_dir_fd=3, dst_dir_fd=4)
8888
os.rename("src", "dst", src_dir_fd=3)
8989
os.rename("src", "dst", dst_dir_fd=4)
90+
91+
# if `dir_fd` is set, suppress the diagnostic
92+
os.readlink(p, dir_fd=1)
93+
os.stat(p, dir_fd=2)
94+
os.unlink(p, dir_fd=3)
95+
os.remove(p, dir_fd=4)
96+
os.rmdir(p, dir_fd=5)
97+
os.mkdir(p, dir_fd=6)
98+
os.chmod(p, dir_fd=7)
99+
# `chmod` can also receive a file descriptor in the first argument
100+
os.chmod(8)
101+
os.chmod(x)
102+
103+
# if `src_dir_fd` or `dst_dir_fd` are set, suppress the diagnostic
104+
os.replace("src", "dst", src_dir_fd=1, dst_dir_fd=2)
105+
os.replace("src", "dst", src_dir_fd=1)
106+
os.replace("src", "dst", dst_dir_fd=2)

crates/ruff_linter/resources/test/fixtures/refurb/FURB116.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import datetime
2+
import sys
3+
14
num = 1337
25

36
def return_num() -> int:
@@ -10,6 +13,7 @@ def return_num() -> int:
1013
print(oct(1337)[2:]) # FURB116
1114
print(hex(1337)[2:]) # FURB116
1215
print(bin(1337)[2:]) # FURB116
16+
print(bin(+1337)[2:]) # FURB116
1317

1418
print(bin(return_num())[2:]) # FURB116 (no autofix)
1519
print(bin(int(f"{num}"))[2:]) # FURB116 (no autofix)
@@ -22,3 +26,19 @@ def return_num() -> int:
2226
# float and complex numbers should be ignored
2327
print(bin(1.0)[2:])
2428
print(bin(3.14j)[2:])
29+
30+
d = datetime.datetime.now(tz=datetime.UTC)
31+
# autofix is display-only
32+
print(bin(d)[2:])
33+
# no autofix for Python 3.11 and earlier, as it introduces a syntax error
34+
print(bin(len("xyz").numerator)[2:])
35+
36+
# autofix is display-only
37+
print(bin({0: 1}[0].numerator)[2:])
38+
# no autofix for Python 3.11 and earlier, as it introduces a syntax error
39+
print(bin(ord("\\").numerator)[2:])
40+
print(hex(sys
41+
.maxunicode)[2:])
42+
43+
# for negatives numbers autofix is display-only
44+
print(bin(-1)[2:])

0 commit comments

Comments
 (0)