Remove F831 (#1495)

This commit is contained in:
Harutaka Kawamura 2022-12-31 13:57:51 +09:00 committed by GitHub
parent 3e23fd1487
commit f7bb5bc858
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 1 additions and 71 deletions

View File

@ -558,7 +558,6 @@ For more, see [Pyflakes](https://pypi.org/project/pyflakes/2.5.0/) on PyPI.
| F821 | UndefinedName | Undefined name `...` | | | F821 | UndefinedName | Undefined name `...` | |
| F822 | UndefinedExport | Undefined name `...` in `__all__` | | | F822 | UndefinedExport | Undefined name `...` in `__all__` | |
| F823 | UndefinedLocal | Local variable `...` referenced before assignment | | | F823 | UndefinedLocal | Local variable `...` referenced before assignment | |
| F831 | DuplicateArgumentName | Duplicate argument name in function definition | |
| F841 | UnusedVariable | Local variable `...` is assigned to but never used | | | F841 | UnusedVariable | Local variable `...` is assigned to but never used | |
| F842 | UnusedAnnotation | Local variable `...` is annotated but never used | | | F842 | UnusedAnnotation | Local variable `...` is annotated but never used | |
| F901 | RaiseNotImplemented | `raise NotImplemented` should be `raise NotImplementedError` | 🛠 | | F901 | RaiseNotImplemented | `raise NotImplemented` should be `raise NotImplementedError` | 🛠 |

View File

@ -1,10 +0,0 @@
def foo(x: int, y: int, x: int) -> None:
pass
def bar(x: int, y: int, *, x: int) -> None:
pass
def baz(x: int, y: int, **x: int) -> None:
pass

View File

@ -652,8 +652,6 @@
"F821", "F821",
"F822", "F822",
"F823", "F823",
"F83",
"F831",
"F84", "F84",
"F841", "F841",
"F842", "F842",

View File

@ -2767,10 +2767,6 @@ where
} }
fn visit_arguments(&mut self, arguments: &'b Arguments) { fn visit_arguments(&mut self, arguments: &'b Arguments) {
if self.settings.enabled.contains(&CheckCode::F831) {
self.checks
.extend(pyflakes::checks::duplicate_arguments(arguments));
}
if self.settings.enabled.contains(&CheckCode::B006) { if self.settings.enabled.contains(&CheckCode::B006) {
flake8_bugbear::plugins::mutable_argument_default(self, arguments); flake8_bugbear::plugins::mutable_argument_default(self, arguments);
} }

View File

@ -92,7 +92,6 @@ pub enum CheckCode {
F821, F821,
F822, F822,
F823, F823,
F831,
F841, F841,
F842, F842,
F901, F901,
@ -730,7 +729,6 @@ pub enum CheckKind {
BreakOutsideLoop, BreakOutsideLoop,
ContinueOutsideLoop, ContinueOutsideLoop,
DefaultExceptNotLast, DefaultExceptNotLast,
DuplicateArgumentName,
ExpressionsInStarAssignment, ExpressionsInStarAssignment,
FStringMissingPlaceholders, FStringMissingPlaceholders,
ForwardAnnotationSyntaxError(String), ForwardAnnotationSyntaxError(String),
@ -1134,7 +1132,6 @@ impl CheckCode {
CheckCode::F821 => CheckKind::UndefinedName("...".to_string()), CheckCode::F821 => CheckKind::UndefinedName("...".to_string()),
CheckCode::F822 => CheckKind::UndefinedExport("...".to_string()), CheckCode::F822 => CheckKind::UndefinedExport("...".to_string()),
CheckCode::F823 => CheckKind::UndefinedLocal("...".to_string()), CheckCode::F823 => CheckKind::UndefinedLocal("...".to_string()),
CheckCode::F831 => CheckKind::DuplicateArgumentName,
CheckCode::F841 => CheckKind::UnusedVariable("...".to_string()), CheckCode::F841 => CheckKind::UnusedVariable("...".to_string()),
CheckCode::F842 => CheckKind::UnusedAnnotation("...".to_string()), CheckCode::F842 => CheckKind::UnusedAnnotation("...".to_string()),
CheckCode::F901 => CheckKind::RaiseNotImplemented, CheckCode::F901 => CheckKind::RaiseNotImplemented,
@ -1631,7 +1628,6 @@ impl CheckCode {
CheckCode::F821 => CheckCategory::Pyflakes, CheckCode::F821 => CheckCategory::Pyflakes,
CheckCode::F822 => CheckCategory::Pyflakes, CheckCode::F822 => CheckCategory::Pyflakes,
CheckCode::F823 => CheckCategory::Pyflakes, CheckCode::F823 => CheckCategory::Pyflakes,
CheckCode::F831 => CheckCategory::Pyflakes,
CheckCode::F841 => CheckCategory::Pyflakes, CheckCode::F841 => CheckCategory::Pyflakes,
CheckCode::F842 => CheckCategory::Pyflakes, CheckCode::F842 => CheckCategory::Pyflakes,
CheckCode::F901 => CheckCategory::Pyflakes, CheckCode::F901 => CheckCategory::Pyflakes,
@ -1768,7 +1764,6 @@ impl CheckKind {
CheckKind::DefaultExceptNotLast => &CheckCode::F707, CheckKind::DefaultExceptNotLast => &CheckCode::F707,
CheckKind::DoNotAssignLambda(..) => &CheckCode::E731, CheckKind::DoNotAssignLambda(..) => &CheckCode::E731,
CheckKind::DoNotUseBareExcept => &CheckCode::E722, CheckKind::DoNotUseBareExcept => &CheckCode::E722,
CheckKind::DuplicateArgumentName => &CheckCode::F831,
CheckKind::FStringMissingPlaceholders => &CheckCode::F541, CheckKind::FStringMissingPlaceholders => &CheckCode::F541,
CheckKind::ForwardAnnotationSyntaxError(..) => &CheckCode::F722, CheckKind::ForwardAnnotationSyntaxError(..) => &CheckCode::F722,
CheckKind::FutureFeatureNotDefined(..) => &CheckCode::F407, CheckKind::FutureFeatureNotDefined(..) => &CheckCode::F407,
@ -2114,9 +2109,6 @@ impl CheckKind {
"Do not assign a `lambda` expression, use a `def`".to_string() "Do not assign a `lambda` expression, use a `def`".to_string()
} }
CheckKind::DoNotUseBareExcept => "Do not use bare `except`".to_string(), CheckKind::DoNotUseBareExcept => "Do not use bare `except`".to_string(),
CheckKind::DuplicateArgumentName => {
"Duplicate argument name in function definition".to_string()
}
CheckKind::ForwardAnnotationSyntaxError(body) => { CheckKind::ForwardAnnotationSyntaxError(body) => {
format!("Syntax error in forward annotation: `{body}`") format!("Syntax error in forward annotation: `{body}`")
} }

View File

@ -283,8 +283,6 @@ pub enum CheckCodePrefix {
F821, F821,
F822, F822,
F823, F823,
F83,
F831,
F84, F84,
F841, F841,
F842, F842,
@ -647,7 +645,6 @@ impl CheckCodePrefix {
CheckCode::F821, CheckCode::F821,
CheckCode::F822, CheckCode::F822,
CheckCode::F823, CheckCode::F823,
CheckCode::F831,
CheckCode::F841, CheckCode::F841,
CheckCode::F842, CheckCode::F842,
CheckCode::F901, CheckCode::F901,
@ -1506,7 +1503,6 @@ impl CheckCodePrefix {
CheckCode::F821, CheckCode::F821,
CheckCode::F822, CheckCode::F822,
CheckCode::F823, CheckCode::F823,
CheckCode::F831,
CheckCode::F841, CheckCode::F841,
CheckCode::F842, CheckCode::F842,
CheckCode::F901, CheckCode::F901,
@ -1640,7 +1636,6 @@ impl CheckCodePrefix {
CheckCode::F821, CheckCode::F821,
CheckCode::F822, CheckCode::F822,
CheckCode::F823, CheckCode::F823,
CheckCode::F831,
CheckCode::F841, CheckCode::F841,
CheckCode::F842, CheckCode::F842,
], ],
@ -1650,8 +1645,6 @@ impl CheckCodePrefix {
CheckCodePrefix::F821 => vec![CheckCode::F821], CheckCodePrefix::F821 => vec![CheckCode::F821],
CheckCodePrefix::F822 => vec![CheckCode::F822], CheckCodePrefix::F822 => vec![CheckCode::F822],
CheckCodePrefix::F823 => vec![CheckCode::F823], CheckCodePrefix::F823 => vec![CheckCode::F823],
CheckCodePrefix::F83 => vec![CheckCode::F831],
CheckCodePrefix::F831 => vec![CheckCode::F831],
CheckCodePrefix::F84 => vec![CheckCode::F841, CheckCode::F842], CheckCodePrefix::F84 => vec![CheckCode::F841, CheckCode::F842],
CheckCodePrefix::F841 => vec![CheckCode::F841], CheckCodePrefix::F841 => vec![CheckCode::F841],
CheckCodePrefix::F842 => vec![CheckCode::F842], CheckCodePrefix::F842 => vec![CheckCode::F842],
@ -3102,8 +3095,6 @@ impl CheckCodePrefix {
CheckCodePrefix::F821 => SuffixLength::Three, CheckCodePrefix::F821 => SuffixLength::Three,
CheckCodePrefix::F822 => SuffixLength::Three, CheckCodePrefix::F822 => SuffixLength::Three,
CheckCodePrefix::F823 => SuffixLength::Three, CheckCodePrefix::F823 => SuffixLength::Three,
CheckCodePrefix::F83 => SuffixLength::Two,
CheckCodePrefix::F831 => SuffixLength::Three,
CheckCodePrefix::F84 => SuffixLength::Two, CheckCodePrefix::F84 => SuffixLength::Two,
CheckCodePrefix::F841 => SuffixLength::Three, CheckCodePrefix::F841 => SuffixLength::Three,
CheckCodePrefix::F842 => SuffixLength::Three, CheckCodePrefix::F842 => SuffixLength::Three,

View File

@ -1,9 +1,8 @@
use std::string::ToString; use std::string::ToString;
use regex::Regex; use regex::Regex;
use rustc_hash::FxHashSet;
use rustpython_parser::ast::{ use rustpython_parser::ast::{
Arg, Arguments, Constant, Excepthandler, ExcepthandlerKind, Expr, ExprKind, Stmt, StmtKind, Constant, Excepthandler, ExcepthandlerKind, Expr, ExprKind, Stmt, StmtKind,
}; };
use crate::ast::types::{Binding, BindingKind, Range, Scope, ScopeKind}; use crate::ast::types::{Binding, BindingKind, Range, Scope, ScopeKind};
@ -125,40 +124,6 @@ pub fn default_except_not_last(handlers: &[Excepthandler]) -> Option<Check> {
None None
} }
/// F831
pub fn duplicate_arguments(arguments: &Arguments) -> Vec<Check> {
let mut checks: Vec<Check> = vec![];
// Collect all the arguments into a single vector.
let mut all_arguments: Vec<&Arg> = arguments
.args
.iter()
.chain(arguments.posonlyargs.iter())
.chain(arguments.kwonlyargs.iter())
.collect();
if let Some(arg) = &arguments.vararg {
all_arguments.push(arg);
}
if let Some(arg) = &arguments.kwarg {
all_arguments.push(arg);
}
// Search for duplicates.
let mut idents: FxHashSet<&str> = FxHashSet::default();
for arg in all_arguments {
let ident = &arg.node.arg;
if idents.contains(ident.as_str()) {
checks.push(Check::new(
CheckKind::DuplicateArgumentName,
Range::from_located(arg),
));
}
idents.insert(ident);
}
checks
}
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
enum DictionaryKey<'a> { enum DictionaryKey<'a> {
Constant(&'a Constant), Constant(&'a Constant),

View File

@ -100,7 +100,6 @@ mod tests {
#[test_case(CheckCode::F821, Path::new("F821_7.py"); "F821_7")] #[test_case(CheckCode::F821, Path::new("F821_7.py"); "F821_7")]
#[test_case(CheckCode::F822, Path::new("F822.py"); "F822")] #[test_case(CheckCode::F822, Path::new("F822.py"); "F822")]
#[test_case(CheckCode::F823, Path::new("F823.py"); "F823")] #[test_case(CheckCode::F823, Path::new("F823.py"); "F823")]
#[test_case(CheckCode::F831, Path::new("F831.py"); "F831")]
#[test_case(CheckCode::F841, Path::new("F841_0.py"); "F841_0")] #[test_case(CheckCode::F841, Path::new("F841_0.py"); "F841_0")]
#[test_case(CheckCode::F841, Path::new("F841_1.py"); "F841_1")] #[test_case(CheckCode::F841, Path::new("F841_1.py"); "F841_1")]
#[test_case(CheckCode::F842, Path::new("F842.py"); "F842")] #[test_case(CheckCode::F842, Path::new("F842.py"); "F842")]