Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd638a2e54 | ||
|
|
fa1459d56e | ||
|
|
d93c5811ea |
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -753,7 +753,7 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
|
||||
|
||||
[[package]]
|
||||
name = "flake8-to-ruff"
|
||||
version = "0.0.250"
|
||||
version = "0.0.251"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap 4.1.6",
|
||||
@@ -1927,7 +1927,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ruff"
|
||||
version = "0.0.250"
|
||||
version = "0.0.251"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bisection",
|
||||
@@ -1983,7 +1983,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ruff_cli"
|
||||
version = "0.0.250"
|
||||
version = "0.0.251"
|
||||
dependencies = [
|
||||
"annotate-snippets 0.9.1",
|
||||
"anyhow",
|
||||
|
||||
@@ -168,7 +168,7 @@ Ruff also works with [pre-commit](https://pre-commit.com):
|
||||
```yaml
|
||||
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
||||
# Ruff version.
|
||||
rev: 'v0.0.250'
|
||||
rev: 'v0.0.251'
|
||||
hooks:
|
||||
- id: ruff
|
||||
```
|
||||
@@ -178,7 +178,7 @@ Or, to enable autofix:
|
||||
```yaml
|
||||
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
||||
# Ruff version.
|
||||
rev: 'v0.0.250'
|
||||
rev: 'v0.0.251'
|
||||
hooks:
|
||||
- id: ruff
|
||||
args: [--fix, --exit-non-zero-on-fix]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "flake8-to-ruff"
|
||||
version = "0.0.250"
|
||||
version = "0.0.251"
|
||||
edition = { workspace = true }
|
||||
rust-version = { workspace = true }
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ruff"
|
||||
version = "0.0.250"
|
||||
version = "0.0.251"
|
||||
authors = ["Charlie Marsh <charlie.r.marsh@gmail.com>"]
|
||||
edition = { workspace = true }
|
||||
rust-version = { workspace = true }
|
||||
|
||||
@@ -18,3 +18,10 @@ class Foo:
|
||||
|
||||
class FooTable(BaseTable):
|
||||
bar = fields.ListField(list)
|
||||
|
||||
|
||||
lambda *args, **kwargs: []
|
||||
|
||||
lambda *args: []
|
||||
|
||||
lambda **kwargs: []
|
||||
|
||||
26
crates/ruff/resources/test/fixtures/pyflakes/F821_9.py
vendored
Normal file
26
crates/ruff/resources/test/fixtures/pyflakes/F821_9.py
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
"""Test: match statements."""
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Car:
|
||||
make: str
|
||||
model: str
|
||||
|
||||
|
||||
def f():
|
||||
match Car("Toyota", "Corolla"):
|
||||
case Car("Toyota", model):
|
||||
print(model)
|
||||
case Car(make, "Corolla"):
|
||||
print(make)
|
||||
|
||||
|
||||
def f(provided: int) -> int:
|
||||
match provided:
|
||||
case True:
|
||||
return captured # F821
|
||||
case [captured, *_]:
|
||||
return captured
|
||||
case captured:
|
||||
return captured
|
||||
@@ -119,3 +119,5 @@ def f(x: int):
|
||||
print("A")
|
||||
case [Bar.A, *_]:
|
||||
print("A")
|
||||
case y:
|
||||
pass
|
||||
|
||||
@@ -10,7 +10,8 @@ use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use rustpython_common::cformat::{CFormatError, CFormatErrorType};
|
||||
use rustpython_parser::ast::{
|
||||
Arg, Arguments, Comprehension, Constant, Excepthandler, ExcepthandlerKind, Expr, ExprContext,
|
||||
ExprKind, KeywordData, Located, Location, Operator, Stmt, StmtKind, Suite,
|
||||
ExprKind, KeywordData, Located, Location, Operator, Pattern, PatternKind, Stmt, StmtKind,
|
||||
Suite,
|
||||
};
|
||||
use rustpython_parser::parser;
|
||||
use smallvec::smallvec;
|
||||
@@ -28,7 +29,7 @@ use crate::ast::types::{
|
||||
RefEquality, Scope, ScopeKind,
|
||||
};
|
||||
use crate::ast::typing::{match_annotated_subscript, Callable, SubscriptKind};
|
||||
use crate::ast::visitor::{walk_excepthandler, Visitor};
|
||||
use crate::ast::visitor::{walk_excepthandler, walk_pattern, Visitor};
|
||||
use crate::ast::{branch_detection, cast, helpers, operations, typing, visitor};
|
||||
use crate::docstrings::definition::{Definition, DefinitionKind, Docstring, Documentable};
|
||||
use crate::registry::{Diagnostic, Rule};
|
||||
@@ -3840,6 +3841,28 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_pattern(&mut self, pattern: &'b Pattern) {
|
||||
if let PatternKind::MatchAs {
|
||||
name: Some(name), ..
|
||||
} = &pattern.node
|
||||
{
|
||||
self.add_binding(
|
||||
name,
|
||||
Binding {
|
||||
kind: BindingKind::Assignment,
|
||||
runtime_usage: None,
|
||||
synthetic_usage: None,
|
||||
typing_usage: None,
|
||||
range: Range::from_located(pattern),
|
||||
source: Some(self.current_stmt().clone()),
|
||||
context: self.execution_context(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
walk_pattern(self, pattern);
|
||||
}
|
||||
|
||||
fn visit_format_spec(&mut self, format_spec: &'b Expr) {
|
||||
match &format_spec.node {
|
||||
ExprKind::JoinedStr { values } => {
|
||||
|
||||
@@ -358,7 +358,12 @@ pub fn prefer_list_builtin(checker: &mut Checker, expr: &Expr) {
|
||||
let ExprKind::Lambda { args, body } = &expr.node else {
|
||||
unreachable!("Expected ExprKind::Lambda");
|
||||
};
|
||||
if args.args.is_empty() {
|
||||
if args.args.is_empty()
|
||||
&& args.kwonlyargs.is_empty()
|
||||
&& args.posonlyargs.is_empty()
|
||||
&& args.vararg.is_none()
|
||||
&& args.kwarg.is_none()
|
||||
{
|
||||
if let ExprKind::List { elts, .. } = &body.node {
|
||||
if elts.is_empty() {
|
||||
let mut diagnostic = Diagnostic::new(PreferListBuiltin, Range::from_located(expr));
|
||||
|
||||
@@ -101,6 +101,7 @@ mod tests {
|
||||
#[test_case(Rule::UndefinedName, Path::new("F821_6.py"); "F821_6")]
|
||||
#[test_case(Rule::UndefinedName, Path::new("F821_7.py"); "F821_7")]
|
||||
#[test_case(Rule::UndefinedName, Path::new("F821_8.pyi"); "F821_8")]
|
||||
#[test_case(Rule::UndefinedName, Path::new("F821_9.py"); "F821_9")]
|
||||
#[test_case(Rule::UndefinedExport, Path::new("F822_0.py"); "F822_0")]
|
||||
#[test_case(Rule::UndefinedExport, Path::new("F822_1.py"); "F822_1")]
|
||||
#[test_case(Rule::UndefinedExport, Path::new("F822_2.py"); "F822_2")]
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
---
|
||||
source: crates/ruff/src/rules/pyflakes/mod.rs
|
||||
expression: diagnostics
|
||||
---
|
||||
- kind:
|
||||
UndefinedName:
|
||||
name: captured
|
||||
location:
|
||||
row: 22
|
||||
column: 19
|
||||
end_location:
|
||||
row: 22
|
||||
column: 27
|
||||
fix: ~
|
||||
parent: ~
|
||||
|
||||
@@ -186,4 +186,15 @@ expression: diagnostics
|
||||
row: 115
|
||||
column: 10
|
||||
parent: ~
|
||||
- kind:
|
||||
UnusedVariable:
|
||||
name: y
|
||||
location:
|
||||
row: 122
|
||||
column: 13
|
||||
end_location:
|
||||
row: 122
|
||||
column: 14
|
||||
fix: ~
|
||||
parent: ~
|
||||
|
||||
|
||||
@@ -222,4 +222,15 @@ expression: diagnostics
|
||||
row: 115
|
||||
column: 10
|
||||
parent: ~
|
||||
- kind:
|
||||
UnusedVariable:
|
||||
name: y
|
||||
location:
|
||||
row: 122
|
||||
column: 13
|
||||
end_location:
|
||||
row: 122
|
||||
column: 14
|
||||
fix: ~
|
||||
parent: ~
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ruff_cli"
|
||||
version = "0.0.250"
|
||||
version = "0.0.251"
|
||||
authors = ["Charlie Marsh <charlie.r.marsh@gmail.com>"]
|
||||
edition = { workspace = true }
|
||||
rust-version = { workspace = true }
|
||||
|
||||
@@ -7,7 +7,7 @@ build-backend = "maturin"
|
||||
|
||||
[project]
|
||||
name = "ruff"
|
||||
version = "0.0.250"
|
||||
version = "0.0.251"
|
||||
description = "An extremely fast Python linter, written in Rust."
|
||||
authors = [{ name = "Charlie Marsh", email = "charlie.r.marsh@gmail.com" }]
|
||||
maintainers = [{ name = "Charlie Marsh", email = "charlie.r.marsh@gmail.com" }]
|
||||
|
||||
Reference in New Issue
Block a user