diff --git a/resources/test/fixtures/flake8_annotations/annotation_presence.py b/resources/test/fixtures/flake8_annotations/annotation_presence.py index 2c880f32ff..e7ab7f997a 100644 --- a/resources/test/fixtures/flake8_annotations/annotation_presence.py +++ b/resources/test/fixtures/flake8_annotations/annotation_presence.py @@ -1,3 +1,5 @@ +from typing import Type + # Error def foo(a, b): pass @@ -31,3 +33,23 @@ def foo(a: int, b: int) -> int: # OK def foo() -> int: pass + + +class Foo: + # OK + def foo(self: "Foo", a: int, b: int) -> int: + pass + + # ANN101 + def foo(self, a: int, b: int) -> int: + pass + + # OK + @classmethod + def foo(cls: Type["Foo"], a: int, b: int) -> int: + pass + + # ANN102 + @classmethod + def foo(cls, a: int, b: int) -> int: + pass diff --git a/src/flake8_annotations/plugins.rs b/src/flake8_annotations/plugins.rs index bc466478fb..9455ebec2a 100644 --- a/src/flake8_annotations/plugins.rs +++ b/src/flake8_annotations/plugins.rs @@ -241,14 +241,14 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V if let Some(arg) = args.args.first() { if arg.node.annotation.is_none() { if visibility::is_classmethod(stmt) { - if checker.settings.enabled.contains(&CheckCode::ANN101) { + if checker.settings.enabled.contains(&CheckCode::ANN102) { checker.add_check(Check::new( CheckKind::MissingTypeCls, Range::from_located(arg), )); } } else { - if checker.settings.enabled.contains(&CheckCode::ANN102) { + if checker.settings.enabled.contains(&CheckCode::ANN101) { checker.add_check(Check::new( CheckKind::MissingTypeSelf, Range::from_located(arg), diff --git a/src/flake8_annotations/snapshots/ruff__flake8_annotations__tests__defaults.snap b/src/flake8_annotations/snapshots/ruff__flake8_annotations__tests__defaults.snap index bba684f7d2..82082382cd 100644 --- a/src/flake8_annotations/snapshots/ruff__flake8_annotations__tests__defaults.snap +++ b/src/flake8_annotations/snapshots/ruff__flake8_annotations__tests__defaults.snap @@ -4,66 +4,82 @@ expression: checks --- - kind: MissingReturnTypePublicFunction location: - row: 2 + row: 4 column: 0 end_location: - row: 7 + row: 9 column: 0 fix: ~ - kind: MissingTypeFunctionArgument location: - row: 2 + row: 4 column: 8 end_location: - row: 2 + row: 4 column: 9 fix: ~ - kind: MissingTypeFunctionArgument location: - row: 2 + row: 4 column: 11 end_location: - row: 2 + row: 4 column: 12 fix: ~ - kind: MissingReturnTypePublicFunction location: - row: 7 + row: 9 column: 0 end_location: - row: 12 + row: 14 column: 0 fix: ~ - kind: MissingTypeFunctionArgument location: - row: 7 + row: 9 column: 16 end_location: - row: 7 + row: 9 column: 17 fix: ~ - kind: MissingTypeFunctionArgument location: - row: 12 + row: 14 column: 16 end_location: - row: 12 + row: 14 column: 17 fix: ~ - kind: MissingReturnTypePublicFunction location: - row: 17 + row: 19 column: 0 end_location: - row: 22 + row: 24 column: 0 fix: ~ - kind: MissingReturnTypePublicFunction location: - row: 22 + row: 24 column: 0 end_location: - row: 27 + row: 29 column: 0 fix: ~ +- kind: MissingTypeSelf + location: + row: 44 + column: 12 + end_location: + row: 44 + column: 16 + fix: ~ +- kind: MissingTypeCls + location: + row: 54 + column: 12 + end_location: + row: 54 + column: 15 + fix: ~