Skip to content

Commit b934d4c

Browse files
committed
Merge remote-tracking branch 'origin/main' into dcreager/typevar-identity
* origin/main: (24 commits) Update Python compatibility from 3.13 to 3.14 in README.md (#20852) [syntax-errors]: break outside loop F701 (#20556) [ty] Treat `Callable`s as bound-method descriptors in special cases (#20802) [ty] Do not bind self to non-positional parameters (#20850) Fix syntax error false positives on parenthesized context managers (#20846) [ty] Remove 'pre-release software' warning (#20817) Render unsupported syntax errors in formatter tests (#20777) [ty] Treat functions, methods, and dynamic types as function-like `Callable`s (#20842) [ty] Move logic for `super()` inference to a new `types::bound_super` submodule (#20840) [ty] Fix false-positive diagnostics on `super()` calls (#20814) [ty] Move `class_member` to `member` module (#20837) [`ruff`] Use DiagnosticTag for more flake8 and numpy rules (#20758) [ty] Prefer declared base class attribute over inferred attribute on subclass (#20764) [ty] Log files that are slow to type check (#20836) Update cargo-bins/cargo-binstall action to v1.15.7 (#20827) Update CodSpeedHQ/action action to v4.1.1 (#20828) Update Rust crate pyproject-toml to v0.13.7 (#20835) Update Rust crate anstream to v0.6.21 (#20829) Update Rust crate libc to v0.2.177 (#20832) Update Rust crate memchr to v2.7.6 (#20834) ...
2 parents 02e7eac + 83b497c commit b934d4c

File tree

100 files changed

+3494
-3085
lines changed

Some content is hidden

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

100 files changed

+3494
-3085
lines changed

.github/workflows/ci.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ jobs:
452452
- name: "Install Rust toolchain"
453453
run: rustup show
454454
- name: "Install cargo-binstall"
455-
uses: cargo-bins/cargo-binstall@38e8f5e4c386b611d51e8aa997b9a06a3c8eb67a # v1.15.6
455+
uses: cargo-bins/cargo-binstall@a66119fbb1c952daba62640c2609111fe0803621 # v1.15.7
456456
- name: "Install cargo-fuzz"
457457
# Download the latest version from quick install and not the github releases because github releases only has MUSL targets.
458458
run: cargo binstall cargo-fuzz --force --disable-strategies crate-meta-data --no-confirm
@@ -703,7 +703,7 @@ jobs:
703703
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
704704
with:
705705
persist-credentials: false
706-
- uses: cargo-bins/cargo-binstall@38e8f5e4c386b611d51e8aa997b9a06a3c8eb67a # v1.15.6
706+
- uses: cargo-bins/cargo-binstall@a66119fbb1c952daba62640c2609111fe0803621 # v1.15.7
707707
- run: cargo binstall --no-confirm cargo-shear
708708
- run: cargo shear
709709

@@ -953,7 +953,7 @@ jobs:
953953
run: cargo codspeed build --features "codspeed,instrumented" --no-default-features -p ruff_benchmark --bench formatter --bench lexer --bench linter --bench parser
954954

955955
- name: "Run benchmarks"
956-
uses: CodSpeedHQ/action@3959e9e296ef25296e93e32afcc97196f966e57f # v4.1.0
956+
uses: CodSpeedHQ/action@6b43a0cd438f6ca5ad26f9ed03ed159ed2df7da9 # v4.1.1
957957
with:
958958
mode: instrumentation
959959
run: cargo codspeed run
@@ -988,7 +988,7 @@ jobs:
988988
run: cargo codspeed build --features "codspeed,instrumented" --no-default-features -p ruff_benchmark --bench ty
989989

990990
- name: "Run benchmarks"
991-
uses: CodSpeedHQ/action@3959e9e296ef25296e93e32afcc97196f966e57f # v4.1.0
991+
uses: CodSpeedHQ/action@6b43a0cd438f6ca5ad26f9ed03ed159ed2df7da9 # v4.1.1
992992
with:
993993
mode: instrumentation
994994
run: cargo codspeed run
@@ -1026,7 +1026,7 @@ jobs:
10261026
run: cargo codspeed build --features "codspeed,walltime" --no-default-features -p ruff_benchmark
10271027

10281028
- name: "Run benchmarks"
1029-
uses: CodSpeedHQ/action@3959e9e296ef25296e93e32afcc97196f966e57f # v4.1.0
1029+
uses: CodSpeedHQ/action@6b43a0cd438f6ca5ad26f9ed03ed159ed2df7da9 # v4.1.1
10301030
env:
10311031
# enabling walltime flamegraphs adds ~6 minutes to the CI time, and they don't
10321032
# appear to provide much useful insight for our walltime benchmarks right now

Cargo.lock

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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ An extremely fast Python linter and code formatter, written in Rust.
2828
- ⚡️ 10-100x faster than existing linters (like Flake8) and formatters (like Black)
2929
- 🐍 Installable via `pip`
3030
- 🛠️ `pyproject.toml` support
31-
- 🤝 Python 3.13 compatibility
31+
- 🤝 Python 3.14 compatibility
3232
- ⚖️ Drop-in parity with [Flake8](https://docs.astral.sh/ruff/faq/#how-does-ruffs-linter-compare-to-flake8), isort, and [Black](https://docs.astral.sh/ruff/faq/#how-does-ruffs-formatter-compare-to-black)
3333
- 📦 Built-in caching, to avoid re-analyzing unchanged files
3434
- 🔧 Fix support, for automatic error correction (e.g., automatically remove unused imports)

crates/ruff_db/src/diagnostic/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use ruff_annotate_snippets::Level as AnnotateLevel;
77
use ruff_text_size::{Ranged, TextRange, TextSize};
88

99
pub use self::render::{
10-
DisplayDiagnostic, DisplayDiagnostics, FileResolver, Input, ceil_char_boundary,
10+
DisplayDiagnostic, DisplayDiagnostics, DummyFileResolver, FileResolver, Input,
11+
ceil_char_boundary,
1112
github::{DisplayGithubDiagnostics, GithubRenderer},
1213
};
1314
use crate::{Db, files::File};

crates/ruff_db/src/diagnostic/render.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,31 @@ pub fn ceil_char_boundary(text: &str, offset: TextSize) -> TextSize {
11701170
.unwrap_or_else(|| TextSize::from(upper_bound))
11711171
}
11721172

1173+
/// A stub implementation of [`FileResolver`] intended for testing.
1174+
pub struct DummyFileResolver;
1175+
1176+
impl FileResolver for DummyFileResolver {
1177+
fn path(&self, _file: File) -> &str {
1178+
unimplemented!()
1179+
}
1180+
1181+
fn input(&self, _file: File) -> Input {
1182+
unimplemented!()
1183+
}
1184+
1185+
fn notebook_index(&self, _file: &UnifiedFile) -> Option<NotebookIndex> {
1186+
None
1187+
}
1188+
1189+
fn is_notebook(&self, _file: &UnifiedFile) -> bool {
1190+
false
1191+
}
1192+
1193+
fn current_directory(&self) -> &Path {
1194+
Path::new(".")
1195+
}
1196+
}
1197+
11731198
#[cfg(test)]
11741199
mod tests {
11751200

crates/ruff_linter/src/checkers/ast/analyze/statement.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
5050
pylint::rules::nonlocal_and_global(checker, nonlocal);
5151
}
5252
}
53-
Stmt::Break(_) => {
54-
if checker.is_rule_enabled(Rule::BreakOutsideLoop) {
55-
pyflakes::rules::break_outside_loop(
56-
checker,
57-
stmt,
58-
&mut checker.semantic.current_statements().skip(1),
59-
);
60-
}
61-
}
6253
Stmt::Continue(_) => {
6354
if checker.is_rule_enabled(Rule::ContinueOutsideLoop) {
6455
pyflakes::rules::continue_outside_loop(

crates/ruff_linter/src/checkers/ast/mod.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -697,13 +697,20 @@ impl SemanticSyntaxContext for Checker<'_> {
697697
}
698698
}
699699
SemanticSyntaxErrorKind::FutureFeatureNotDefined(name) => {
700+
// F407
700701
if self.is_rule_enabled(Rule::FutureFeatureNotDefined) {
701702
self.report_diagnostic(
702703
pyflakes::rules::FutureFeatureNotDefined { name },
703704
error.range,
704705
);
705706
}
706707
}
708+
SemanticSyntaxErrorKind::BreakOutsideLoop => {
709+
// F701
710+
if self.is_rule_enabled(Rule::BreakOutsideLoop) {
711+
self.report_diagnostic(pyflakes::rules::BreakOutsideLoop, error.range);
712+
}
713+
}
707714
SemanticSyntaxErrorKind::ReboundComprehensionVariable
708715
| SemanticSyntaxErrorKind::DuplicateTypeParameter
709716
| SemanticSyntaxErrorKind::MultipleCaseAssignment(_)
@@ -811,19 +818,40 @@ impl SemanticSyntaxContext for Checker<'_> {
811818
}
812819
)
813820
}
821+
822+
fn in_loop_context(&self) -> bool {
823+
let mut child = self.semantic.current_statement();
824+
825+
for parent in self.semantic.current_statements().skip(1) {
826+
match parent {
827+
Stmt::For(ast::StmtFor { orelse, .. })
828+
| Stmt::While(ast::StmtWhile { orelse, .. }) => {
829+
if !orelse.contains(child) {
830+
return true;
831+
}
832+
}
833+
Stmt::FunctionDef(_) | Stmt::ClassDef(_) => {
834+
break;
835+
}
836+
_ => {}
837+
}
838+
child = parent;
839+
}
840+
false
841+
}
814842
}
815843

816844
impl<'a> Visitor<'a> for Checker<'a> {
817845
fn visit_stmt(&mut self, stmt: &'a Stmt) {
846+
// Step 0: Pre-processing
847+
self.semantic.push_node(stmt);
848+
818849
// For functions, defer semantic syntax error checks until the body of the function is
819850
// visited
820851
if !stmt.is_function_def_stmt() {
821852
self.with_semantic_checker(|semantic, context| semantic.visit_stmt(stmt, context));
822853
}
823854

824-
// Step 0: Pre-processing
825-
self.semantic.push_node(stmt);
826-
827855
// For Jupyter Notebooks, we'll reset the `IMPORT_BOUNDARY` flag when
828856
// we encounter a cell boundary.
829857
if self.source_type.is_ipynb()

crates/ruff_linter/src/fs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ use crate::settings::types::CompiledPerFileIgnoreList;
1111
pub fn get_cwd() -> &'static Path {
1212
#[cfg(target_arch = "wasm32")]
1313
{
14-
static CWD: std::sync::LazyLock<PathBuf> = std::sync::LazyLock::new(|| PathBuf::from("."));
15-
&CWD
14+
Path::new(".")
1615
}
1716
#[cfg(not(target_arch = "wasm32"))]
1817
path_absolutize::path_dedot::CWD.as_path()

crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_function_call.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,9 +1091,12 @@ fn suspicious_function(
10911091
] => checker.report_diagnostic_if_enabled(SuspiciousInsecureCipherModeUsage, range),
10921092

10931093
// Mktemp
1094-
["tempfile", "mktemp"] => {
1095-
checker.report_diagnostic_if_enabled(SuspiciousMktempUsage, range)
1096-
}
1094+
["tempfile", "mktemp"] => checker
1095+
.report_diagnostic_if_enabled(SuspiciousMktempUsage, range)
1096+
.map(|mut diagnostic| {
1097+
diagnostic.add_primary_tag(ruff_db::diagnostic::DiagnosticTag::Deprecated);
1098+
diagnostic
1099+
}),
10971100

10981101
// Eval
10991102
["" | "builtins", "eval"] => {

crates/ruff_linter/src/rules/flake8_pyi/rules/bytestring_usage.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ pub(crate) fn bytestring_attribute(checker: &Checker, attribute: &Expr) {
7474
["collections", "abc", "ByteString"] => ByteStringOrigin::CollectionsAbc,
7575
_ => return,
7676
};
77-
checker.report_diagnostic(ByteStringUsage { origin }, attribute.range());
77+
let mut diagnostic = checker.report_diagnostic(ByteStringUsage { origin }, attribute.range());
78+
diagnostic.add_primary_tag(ruff_db::diagnostic::DiagnosticTag::Deprecated);
7879
}
7980

8081
/// PYI057
@@ -94,7 +95,9 @@ pub(crate) fn bytestring_import(checker: &Checker, import_from: &ast::StmtImport
9495

9596
for name in names {
9697
if name.name.as_str() == "ByteString" {
97-
checker.report_diagnostic(ByteStringUsage { origin }, name.range());
98+
let mut diagnostic =
99+
checker.report_diagnostic(ByteStringUsage { origin }, name.range());
100+
diagnostic.add_primary_tag(ruff_db::diagnostic::DiagnosticTag::Deprecated);
98101
}
99102
}
100103
}

0 commit comments

Comments
 (0)