---
source: crates/ruff_linter/src/rules/flake8_annotations/mod.rs
---
ANN201 [*] Missing return type annotation for public function `foo`
 --> annotation_presence.py:5:5
  |
4 | # Error
5 | def foo(a, b):
  |     ^^^
6 |     pass
  |
help: Add return type annotation: `None`
  |
4 | # Error
  - def foo(a, b):
5 + def foo(a, b) -> None:
6 |     pass
  |
note: This is an unsafe fix and may change runtime behavior

ANN001 Missing type annotation for function argument `a`
 --> annotation_presence.py:5:9
  |
4 | # Error
5 | def foo(a, b):
  |         ^
6 |     pass
  |

ANN001 Missing type annotation for function argument `b`
 --> annotation_presence.py:5:12
  |
4 | # Error
5 | def foo(a, b):
  |            ^
6 |     pass
  |

ANN201 [*] Missing return type annotation for public function `foo`
  --> annotation_presence.py:10:5
   |
 9 | # Error
10 | def foo(a: int, b):
   |     ^^^
11 |     pass
   |
help: Add return type annotation: `None`
   |
9  | # Error
   - def foo(a: int, b):
10 + def foo(a: int, b) -> None:
11 |     pass
   |
note: This is an unsafe fix and may change runtime behavior

ANN001 Missing type annotation for function argument `b`
  --> annotation_presence.py:10:17
   |
 9 | # Error
10 | def foo(a: int, b):
   |                 ^
11 |     pass
   |

ANN001 Missing type annotation for function argument `b`
  --> annotation_presence.py:15:17
   |
14 | # Error
15 | def foo(a: int, b) -> int:
   |                 ^
16 |     pass
   |

ANN201 [*] Missing return type annotation for public function `foo`
  --> annotation_presence.py:20:5
   |
19 | # Error
20 | def foo(a: int, b: int):
   |     ^^^
21 |     pass
   |
help: Add return type annotation: `None`
   |
19 | # Error
   - def foo(a: int, b: int):
20 + def foo(a: int, b: int) -> None:
21 |     pass
   |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `foo`
  --> annotation_presence.py:25:5
   |
24 | # Error
25 | def foo():
   |     ^^^
26 |     pass
   |
help: Add return type annotation: `None`
   |
24 | # Error
   - def foo():
25 + def foo() -> None:
26 |     pass
   |
note: This is an unsafe fix and may change runtime behavior

ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a`
  --> annotation_presence.py:45:12
   |
44 | # ANN401
45 | def foo(a: Any, *args: str, **kwargs: str) -> int:
   |            ^^^
46 |     pass
   |

ANN401 Dynamically typed expressions (typing.Any) are disallowed in `foo`
  --> annotation_presence.py:50:47
   |
49 | # ANN401
50 | def foo(a: int, *args: str, **kwargs: str) -> Any:
   |                                               ^^^
51 |     pass
   |

ANN401 Dynamically typed expressions (typing.Any) are disallowed in `*args`
  --> annotation_presence.py:55:24
   |
54 | # ANN401
55 | def foo(a: int, *args: Any, **kwargs: Any) -> int:
   |                        ^^^
56 |     pass
   |

ANN401 Dynamically typed expressions (typing.Any) are disallowed in `**kwargs`
  --> annotation_presence.py:55:39
   |
54 | # ANN401
55 | def foo(a: int, *args: Any, **kwargs: Any) -> int:
   |                                       ^^^
56 |     pass
   |

ANN401 Dynamically typed expressions (typing.Any) are disallowed in `*args`
  --> annotation_presence.py:60:24
   |
59 | # ANN401
60 | def foo(a: int, *args: Any, **kwargs: str) -> int:
   |                        ^^^
61 |     pass
   |

ANN401 Dynamically typed expressions (typing.Any) are disallowed in `**kwargs`
  --> annotation_presence.py:65:39
   |
64 | # ANN401
65 | def foo(a: int, *args: str, **kwargs: Any) -> int:
   |                                       ^^^
66 |     pass
   |

ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a`
  --> annotation_presence.py:79:29
   |
78 |     # ANN401
79 |     def foo(self: "Foo", a: Any, *params: str, **options: str) -> int:
   |                             ^^^
80 |         pass
   |

ANN401 Dynamically typed expressions (typing.Any) are disallowed in `foo`
  --> annotation_presence.py:83:67
   |
82 |     # ANN401
83 |     def foo(self: "Foo", a: int, *params: str, **options: str) -> Any:
   |                                                                   ^^^
84 |         pass
   |

ANN401 Dynamically typed expressions (typing.Any) are disallowed in `*params`
  --> annotation_presence.py:87:43
   |
86 |     # ANN401
87 |     def foo(self: "Foo", a: int, *params: Any, **options: Any) -> int:
   |                                           ^^^
88 |         pass
   |

ANN401 Dynamically typed expressions (typing.Any) are disallowed in `**options`
  --> annotation_presence.py:87:59
   |
86 |     # ANN401
87 |     def foo(self: "Foo", a: int, *params: Any, **options: Any) -> int:
   |                                                           ^^^
88 |         pass
   |

ANN401 Dynamically typed expressions (typing.Any) are disallowed in `*params`
  --> annotation_presence.py:91:43
   |
90 |     # ANN401
91 |     def foo(self: "Foo", a: int, *params: Any, **options: str) -> int:
   |                                           ^^^
92 |         pass
   |

ANN401 Dynamically typed expressions (typing.Any) are disallowed in `**options`
  --> annotation_presence.py:95:59
   |
94 |     # ANN401
95 |     def foo(self: "Foo", a: int, *params: str, **options: Any) -> int:
   |                                                           ^^^
96 |         pass
   |

ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a`
   --> annotation_presence.py:149:10
    |
148 | # ANN401
149 | def f(a: Any | int) -> None: ...
    |          ^^^^^^^^^
150 | def f(a: int | Any) -> None: ...
151 | def f(a: Union[str, bytes, Any]) -> None: ...
    |

ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a`
   --> annotation_presence.py:150:10
    |
148 | # ANN401
149 | def f(a: Any | int) -> None: ...
150 | def f(a: int | Any) -> None: ...
    |          ^^^^^^^^^
151 | def f(a: Union[str, bytes, Any]) -> None: ...
152 | def f(a: Optional[Any]) -> None: ...
    |

ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a`
   --> annotation_presence.py:151:10
    |
149 | def f(a: Any | int) -> None: ...
150 | def f(a: int | Any) -> None: ...
151 | def f(a: Union[str, bytes, Any]) -> None: ...
    |          ^^^^^^^^^^^^^^^^^^^^^^
152 | def f(a: Optional[Any]) -> None: ...
153 | def f(a: Annotated[Any, ...]) -> None: ...
    |

ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a`
   --> annotation_presence.py:152:10
    |
150 | def f(a: int | Any) -> None: ...
151 | def f(a: Union[str, bytes, Any]) -> None: ...
152 | def f(a: Optional[Any]) -> None: ...
    |          ^^^^^^^^^^^^^
153 | def f(a: Annotated[Any, ...]) -> None: ...
154 | def f(a: "Union[str, bytes, Any]") -> None: ...
    |

ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a`
   --> annotation_presence.py:153:10
    |
151 | def f(a: Union[str, bytes, Any]) -> None: ...
152 | def f(a: Optional[Any]) -> None: ...
153 | def f(a: Annotated[Any, ...]) -> None: ...
    |          ^^^^^^^^^^^^^^^^^^^
154 | def f(a: "Union[str, bytes, Any]") -> None: ...
    |

ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a`
   --> annotation_presence.py:154:10
    |
152 | def f(a: Optional[Any]) -> None: ...
153 | def f(a: Annotated[Any, ...]) -> None: ...
154 | def f(a: "Union[str, bytes, Any]") -> None: ...
    |          ^^^^^^^^^^^^^^^^^^^^^^^^
    |

ANN204 [*] Missing return type annotation for special method `__init__`
   --> annotation_presence.py:159:9
    |
157 | class Foo:
158 |     @decorator()
159 |     def __init__(self: "Foo", foo: int):
    |         ^^^^^^^^
160 |        ...
    |
help: Add return type annotation: `None`
    |
158 |     @decorator()
    -     def __init__(self: "Foo", foo: int):
159 +     def __init__(self: "Foo", foo: int) -> None:
160 |        ...
    |
note: This is an unsafe fix and may change runtime behavior

ANN204 [*] Missing return type annotation for special method `__init__`
   --> annotation_presence.py:165:9
    |
163 | # Regression test for: https://github.com/astral-sh/ruff/issues/7711
164 | class Class:
165 |     def __init__(self):
    |         ^^^^^^^^
166 |         print(f"{self.attr=}")
    |
help: Add return type annotation: `None`
    |
164 | class Class:
    -     def __init__(self):
165 +     def __init__(self) -> None:
166 |         print(f"{self.attr=}")
    |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `quoted_escape`
   --> annotation_presence.py:172:5
    |
170 | # A quoted annotation containing a nested string with an escape sequence
171 | # should not cause a stack overflow.
172 | def quoted_escape(x: "'in\x74'"): pass
    |     ^^^^^^^^^^^^^
    |
help: Add return type annotation: `None`
    |
171 | # should not cause a stack overflow.
    - def quoted_escape(x: "'in\x74'"): pass
172 + def quoted_escape(x: "'in\x74'") -> None: pass
    |
note: This is an unsafe fix and may change runtime behavior

ANN401 Dynamically typed expressions (typing.Any) are disallowed in `x`
   --> annotation_presence.py:172:22
    |
170 | # A quoted annotation containing a nested string with an escape sequence
171 | # should not cause a stack overflow.
172 | def quoted_escape(x: "'in\x74'"): pass
    |                      ^^^^^^^^^^
    |
