mirror of https://github.com/astral-sh/ruff
Ignore certain flake8-pyi errors within function bodies (#4029)
This commit is contained in:
parent
827cbe7f97
commit
10d5415bcb
|
|
@ -11,3 +11,7 @@ _T = TypeVar("_T") # OK
|
|||
_TTuple = TypeVarTuple("_TTuple") # OK
|
||||
|
||||
_P = ParamSpec("_P") # OK
|
||||
|
||||
|
||||
def f():
|
||||
T = TypeVar("T") # OK
|
||||
|
|
|
|||
|
|
@ -11,3 +11,6 @@ _T = TypeVar("_T") # OK
|
|||
_TTuple = TypeVarTuple("_TTuple") # OK
|
||||
|
||||
_P = ParamSpec("_P") # OK
|
||||
|
||||
def f():
|
||||
T = TypeVar("T") # OK
|
||||
|
|
|
|||
|
|
@ -46,3 +46,7 @@ field229: dict[int, int] = {1: 2, **{3: 4}} # Y015 Only simple default values a
|
|||
field23 = "foo" + "bar" # Y015 Only simple default values are allowed for assignments
|
||||
field24 = b"foo" + b"bar" # Y015 Only simple default values are allowed for assignments
|
||||
field25 = 5 * 5 # Y015 Only simple default values are allowed for assignments
|
||||
|
||||
# We shouldn't emit Y015 within functions
|
||||
def f():
|
||||
field26: list[int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
|
||||
|
|
|
|||
|
|
@ -53,3 +53,7 @@ field229: dict[int, int] = {1: 2, **{3: 4}} # Y015 Only simple default values a
|
|||
field23 = "foo" + "bar" # Y015 Only simple default values are allowed for assignments
|
||||
field24 = b"foo" + b"bar" # Y015 Only simple default values are allowed for assignments
|
||||
field25 = 5 * 5 # Y015 Only simple default values are allowed for assignments
|
||||
|
||||
# We shouldn't emit Y015 within functions
|
||||
def f():
|
||||
field26: list[int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
|
||||
|
|
|
|||
|
|
@ -1791,12 +1791,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
if self.is_stub {
|
||||
if self.settings.rules.enabled(Rule::UnprefixedTypeParam) {
|
||||
flake8_pyi::rules::prefix_type_params(self, value, targets);
|
||||
}
|
||||
}
|
||||
|
||||
if self.settings.rules.enabled(Rule::GlobalStatement) {
|
||||
for target in targets.iter() {
|
||||
if let ExprKind::Name { id, .. } = &target.node {
|
||||
|
|
@ -1837,8 +1831,20 @@ where
|
|||
}
|
||||
|
||||
if self.is_stub {
|
||||
if self.settings.rules.enabled(Rule::AssignmentDefaultInStub) {
|
||||
flake8_pyi::rules::assignment_default_in_stub(self, value, None);
|
||||
if self
|
||||
.settings
|
||||
.rules
|
||||
.any_enabled(&[Rule::UnprefixedTypeParam, Rule::AssignmentDefaultInStub])
|
||||
{
|
||||
// Ignore assignments in function bodies; those are covered by other rules.
|
||||
if !self.ctx.scopes().any(|scope| scope.kind.is_function()) {
|
||||
if self.settings.rules.enabled(Rule::UnprefixedTypeParam) {
|
||||
flake8_pyi::rules::prefix_type_params(self, value, targets);
|
||||
}
|
||||
if self.settings.rules.enabled(Rule::AssignmentDefaultInStub) {
|
||||
flake8_pyi::rules::assignment_default_in_stub(self, value, None);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1874,11 +1880,14 @@ where
|
|||
if self.is_stub {
|
||||
if let Some(value) = value {
|
||||
if self.settings.rules.enabled(Rule::AssignmentDefaultInStub) {
|
||||
flake8_pyi::rules::assignment_default_in_stub(
|
||||
self,
|
||||
value,
|
||||
Some(annotation),
|
||||
);
|
||||
// Ignore assignments in function bodies; those are covered by other rules.
|
||||
if !self.ctx.scopes().any(|scope| scope.kind.is_function()) {
|
||||
flake8_pyi::rules::assignment_default_in_stub(
|
||||
self,
|
||||
value,
|
||||
Some(annotation),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -187,6 +187,7 @@ PYI015.pyi:53:11: PYI015 [*] Only simple default values allowed for assignments
|
|||
53 |+field23 = ... # Y015 Only simple default values are allowed for assignments
|
||||
54 54 | field24 = b"foo" + b"bar" # Y015 Only simple default values are allowed for assignments
|
||||
55 55 | field25 = 5 * 5 # Y015 Only simple default values are allowed for assignments
|
||||
56 56 |
|
||||
|
||||
PYI015.pyi:54:11: PYI015 [*] Only simple default values allowed for assignments
|
||||
|
|
||||
|
|
@ -205,6 +206,8 @@ PYI015.pyi:54:11: PYI015 [*] Only simple default values allowed for assignments
|
|||
54 |-field24 = b"foo" + b"bar" # Y015 Only simple default values are allowed for assignments
|
||||
54 |+field24 = ... # Y015 Only simple default values are allowed for assignments
|
||||
55 55 | field25 = 5 * 5 # Y015 Only simple default values are allowed for assignments
|
||||
56 56 |
|
||||
57 57 | # We shouldn't emit Y015 within functions
|
||||
|
||||
PYI015.pyi:55:11: PYI015 [*] Only simple default values allowed for assignments
|
||||
|
|
||||
|
|
@ -212,6 +215,8 @@ PYI015.pyi:55:11: PYI015 [*] Only simple default values allowed for assignments
|
|||
56 | field24 = b"foo" + b"bar" # Y015 Only simple default values are allowed for assignments
|
||||
57 | field25 = 5 * 5 # Y015 Only simple default values are allowed for assignments
|
||||
| ^^^^^ PYI015
|
||||
58 |
|
||||
59 | # We shouldn't emit Y015 within functions
|
||||
|
|
||||
= help: Replace default value with `...`
|
||||
|
||||
|
|
@ -221,5 +226,8 @@ PYI015.pyi:55:11: PYI015 [*] Only simple default values allowed for assignments
|
|||
54 54 | field24 = b"foo" + b"bar" # Y015 Only simple default values are allowed for assignments
|
||||
55 |-field25 = 5 * 5 # Y015 Only simple default values are allowed for assignments
|
||||
55 |+field25 = ... # Y015 Only simple default values are allowed for assignments
|
||||
56 56 |
|
||||
57 57 | # We shouldn't emit Y015 within functions
|
||||
58 58 | def f():
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ impl From<ScopeId> for usize {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, is_macro::Is)]
|
||||
pub enum ScopeKind<'a> {
|
||||
Class(ClassDef<'a>),
|
||||
Function(FunctionDef<'a>),
|
||||
|
|
|
|||
Loading…
Reference in New Issue