mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:25:17 +00:00
Respect self as positional-only argument in annotation rules (#2927)
This commit is contained in:
parent
57a5071b4e
commit
cb971d3a48
4 changed files with 18 additions and 4 deletions
|
@ -103,3 +103,7 @@ class Foo:
|
|||
@classmethod
|
||||
def foo(cls, a: int, b: int) -> int:
|
||||
pass
|
||||
|
||||
# ANN101
|
||||
def foo(self, /, a: int, b: int) -> int:
|
||||
pass
|
||||
|
|
|
@ -475,9 +475,9 @@ pub fn definition(
|
|||
|
||||
// ANN001, ANN401
|
||||
for arg in args
|
||||
.args
|
||||
.posonlyargs
|
||||
.iter()
|
||||
.chain(args.posonlyargs.iter())
|
||||
.chain(args.args.iter())
|
||||
.chain(args.kwonlyargs.iter())
|
||||
.skip(
|
||||
// If this is a non-static method, skip `cls` or `self`.
|
||||
|
@ -581,7 +581,7 @@ pub fn definition(
|
|||
|
||||
// ANN101, ANN102
|
||||
if is_method && !visibility::is_staticmethod(checker, cast::decorator_list(stmt)) {
|
||||
if let Some(arg) = args.args.first() {
|
||||
if let Some(arg) = args.posonlyargs.first().or_else(|| args.args.first()) {
|
||||
if arg.node.annotation.is_none() {
|
||||
if visibility::is_classmethod(checker, cast::decorator_list(stmt)) {
|
||||
if checker.settings.rules.enabled(&Rule::MissingTypeCls) {
|
||||
|
|
|
@ -244,4 +244,15 @@ expression: diagnostics
|
|||
column: 15
|
||||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
MissingTypeSelf:
|
||||
name: self
|
||||
location:
|
||||
row: 108
|
||||
column: 12
|
||||
end_location:
|
||||
row: 108
|
||||
column: 16
|
||||
fix: ~
|
||||
parent: ~
|
||||
|
||||
|
|
|
@ -225,7 +225,6 @@ fn sorted_child_nodes_inner<'a>(node: &Node<'a>, result: &mut Vec<Node<'a>>) {
|
|||
for decorator in decorator_list {
|
||||
result.push(Node::Expr(decorator));
|
||||
}
|
||||
// TODO(charlie): Retain order.
|
||||
for arg in &args.posonlyargs {
|
||||
if let Some(expr) = &arg.node.annotation {
|
||||
result.push(Node::Expr(expr));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue