---
source: crates/ruff_linter/src/rules/flake8_annotations/mod.rs
---
ANN201 [*] Missing return type annotation for public function `func`
 --> auto_return_type.py:1:5
  |
1 | def func():
  |     ^^^^
2 |     return 1
  |
help: Add return type annotation: `int`
  |
  - def func():
1 + def func() -> int:
2 |     return 1
  |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
 --> auto_return_type.py:5:5
  |
5 | def func():
  |     ^^^^
6 |     return 1.5
  |
help: Add return type annotation: `float`
  |
4 |
  - def func():
5 + def func() -> float:
6 |     return 1.5
  |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
  --> auto_return_type.py:9:5
   |
 9 | def func(x: int):
   |     ^^^^
10 |     if x > 0:
11 |         return 1
   |
help: Add return type annotation: `float`
   |
8  |
   - def func(x: int):
9  + def func(x: int) -> float:
10 |     if x > 0:
   |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
  --> auto_return_type.py:16:5
   |
16 | def func():
   |     ^^^^
17 |     return True
   |
help: Add return type annotation: `bool`
   |
15 |
   - def func():
16 + def func() -> bool:
17 |     return True
   |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
  --> auto_return_type.py:20:5
   |
20 | def func(x: int):
   |     ^^^^
21 |     if x > 0:
22 |         return None
   |
help: Add return type annotation: `None`
   |
19 |
   - def func(x: int):
20 + def func(x: int) -> None:
21 |     if x > 0:
   |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
  --> auto_return_type.py:27:5
   |
27 | def func(x: int):
   |     ^^^^
28 |     return 1 or 2.5 if x > 0 else 1.5 or "str"
   |
help: Add return type annotation: `str | float`
   |
26 |
   - def func(x: int):
27 + def func(x: int) -> str | float:
28 |     return 1 or 2.5 if x > 0 else 1.5 or "str"
   |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
  --> auto_return_type.py:31:5
   |
31 | def func(x: int):
   |     ^^^^
32 |     return 1 + 2.5 if x > 0 else 1.5 or "str"
   |
help: Add return type annotation: `str | float`
   |
30 |
   - def func(x: int):
31 + def func(x: int) -> str | float:
32 |     return 1 + 2.5 if x > 0 else 1.5 or "str"
   |
note: This is an unsafe fix and may change runtime behavior

ANN201 Missing return type annotation for public function `func`
  --> auto_return_type.py:35:5
   |
35 | def func(x: int):
   |     ^^^^
36 |     if not x:
37 |         return None
   |
help: Add return type annotation

ANN201 Missing return type annotation for public function `func`
  --> auto_return_type.py:41:5
   |
41 | def func(x: int):
   |     ^^^^
42 |     return {"foo": 1}
   |
help: Add return type annotation

ANN201 [*] Missing return type annotation for public function `func`
  --> auto_return_type.py:45:5
   |
45 | def func(x: int):
   |     ^^^^
46 |     if not x:
47 |         return 1
   |
help: Add return type annotation: `int`
   |
44 |
   - def func(x: int):
45 + def func(x: int) -> int:
46 |     if not x:
   |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
  --> auto_return_type.py:52:5
   |
52 | def func(x: int):
   |     ^^^^
53 |     if not x:
54 |         return 1
   |
help: Add return type annotation: `int | None`
   |
51 |
   - def func(x: int):
52 + def func(x: int) -> int | None:
53 |     if not x:
   |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
  --> auto_return_type.py:59:5
   |
59 | def func(x: int):
   |     ^^^^
60 |     if not x:
61 |         return 1
   |
help: Add return type annotation: `str | int | None`
   |
58 |
   - def func(x: int):
59 + def func(x: int) -> str | int | None:
60 |     if not x:
   |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
  --> auto_return_type.py:68:5
   |
68 | def func(x: int):
   |     ^^^^
69 |     if x:
70 |         return 1
   |
help: Add return type annotation: `int | None`
   |
67 |
   - def func(x: int):
68 + def func(x: int) -> int | None:
69 |     if x:
   |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
  --> auto_return_type.py:73:5
   |
73 | def func():
   |     ^^^^
74 |     x = 1
   |
help: Add return type annotation: `None`
   |
72 |
   - def func():
73 + def func() -> None:
74 |     x = 1
   |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
  --> auto_return_type.py:77:5
   |
77 | def func(x: int):
   |     ^^^^
78 |     if x > 0:
79 |         return 1
   |
help: Add return type annotation: `int | None`
   |
76 |
   - def func(x: int):
77 + def func(x: int) -> int | None:
78 |     if x > 0:
   |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
  --> auto_return_type.py:82:5
   |
82 | def func(x: int):
   |     ^^^^
83 |     match x:
84 |         case [1, 2, 3]:
   |
help: Add return type annotation: `str | int | None`
   |
81 |
   - def func(x: int):
82 + def func(x: int) -> str | int | None:
83 |     match x:
   |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
  --> auto_return_type.py:90:5
   |
90 | def func(x: int):
   |     ^^^^
91 |     for i in range(5):
92 |         if i > 0:
   |
help: Add return type annotation: `int | None`
   |
89 |
   - def func(x: int):
90 + def func(x: int) -> int | None:
91 |     for i in range(5):
   |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
  --> auto_return_type.py:96:5
   |
96 | def func(x: int):
   |     ^^^^
97 |     for i in range(5):
98 |         if i > 0:
   |
help: Add return type annotation: `int`
   |
95 |
   - def func(x: int):
96 + def func(x: int) -> int:
97 |     for i in range(5):
   |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
   --> auto_return_type.py:104:5
    |
104 | def func(x: int):
    |     ^^^^
105 |     for i in range(5):
106 |         if i > 0:
    |
help: Add return type annotation: `int | None`
    |
103 |
    - def func(x: int):
104 + def func(x: int) -> int | None:
105 |     for i in range(5):
    |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
   --> auto_return_type.py:112:5
    |
112 | def func(x: int):
    |     ^^^^
113 |     try:
114 |         pass
    |
help: Add return type annotation: `int | None`
    |
111 |
    - def func(x: int):
112 + def func(x: int) -> int | None:
113 |     try:
    |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
   --> auto_return_type.py:119:5
    |
119 | def func(x: int):
    |     ^^^^
120 |     try:
121 |         pass
    |
help: Add return type annotation: `int`
    |
118 |
    - def func(x: int):
119 + def func(x: int) -> int:
120 |     try:
    |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
   --> auto_return_type.py:128:5
    |
128 | def func(x: int):
    |     ^^^^
129 |     try:
130 |         pass
    |
help: Add return type annotation: `int`
    |
127 |
    - def func(x: int):
128 + def func(x: int) -> int:
129 |     try:
    |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
   --> auto_return_type.py:137:5
    |
137 | def func(x: int):
    |     ^^^^
138 |     try:
139 |         return 1
    |
help: Add return type annotation: `int | None`
    |
136 |
    - def func(x: int):
137 + def func(x: int) -> int | None:
138 |     try:
    |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
   --> auto_return_type.py:146:5
    |
146 | def func(x: int):
    |     ^^^^
147 |     while x > 0:
148 |         break
    |
help: Add return type annotation: `int | None`
    |
145 |
    - def func(x: int):
146 + def func(x: int) -> int | None:
147 |     while x > 0:
    |
note: This is an unsafe fix and may change runtime behavior

ANN201 Missing return type annotation for public function `method`
   --> auto_return_type.py:158:9
    |
156 | class Foo(abc.ABC):
157 |     @abstractmethod
158 |     def method(self):
    |         ^^^^^^
159 |         pass
    |
help: Add return type annotation

ANN201 Missing return type annotation for public function `method`
   --> auto_return_type.py:162:9
    |
161 |     @abc.abstractmethod
162 |     def method(self):
    |         ^^^^^^
163 |         """Docstring."""
    |
help: Add return type annotation

ANN201 Missing return type annotation for public function `method`
   --> auto_return_type.py:166:9
    |
165 |     @abc.abstractmethod
166 |     def method(self):
    |         ^^^^^^
167 |         ...
    |
help: Add return type annotation

ANN205 Missing return type annotation for staticmethod `method`
   --> auto_return_type.py:171:9
    |
169 |     @staticmethod
170 |     @abstractmethod
171 |     def method():
    |         ^^^^^^
172 |         pass
    |
help: Add return type annotation

ANN206 Missing return type annotation for classmethod `method`
   --> auto_return_type.py:176:9
    |
174 |     @classmethod
175 |     @abstractmethod
176 |     def method(cls):
    |         ^^^^^^
177 |         pass
    |
help: Add return type annotation

ANN201 [*] Missing return type annotation for public function `method`
   --> auto_return_type.py:180:9
    |
179 |     @abstractmethod
180 |     def method(self):
    |         ^^^^^^
181 |         if self.x > 0:
182 |             return 1
    |
help: Add return type annotation: `float`
    |
179 |     @abstractmethod
    -     def method(self):
180 +     def method(self) -> float:
181 |         if self.x > 0:
    |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
   --> auto_return_type.py:187:5
    |
187 | def func(x: int):
    |     ^^^^
188 |     try:
189 |         pass
    |
help: Add return type annotation: `int | None`
    |
186 |
    - def func(x: int):
187 + def func(x: int) -> int | None:
188 |     try:
    |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
   --> auto_return_type.py:194:5
    |
194 | def func(x: int):
    |     ^^^^
195 |     try:
196 |         pass
    |
help: Add return type annotation: `int`
    |
193 |
    - def func(x: int):
194 + def func(x: int) -> int:
195 |     try:
    |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
   --> auto_return_type.py:203:5
    |
203 | def func(x: int):
    |     ^^^^
204 |     if not x:
205 |         raise ValueError
    |
help: Add return type annotation: `Never`
    |
153 | from abc import abstractmethod
154 + from typing import Never
155 |
--------------------------------------------------------------------------------
203 |
    - def func(x: int):
204 + def func(x: int) -> Never:
205 |     if not x:
    |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
   --> auto_return_type.py:210:5
    |
210 | def func(x: int):
    |     ^^^^
211 |     if not x:
212 |         raise ValueError
    |
help: Add return type annotation: `int`
    |
209 |
    - def func(x: int):
210 + def func(x: int) -> int:
211 |     if not x:
    |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
   --> auto_return_type.py:234:5
    |
234 | def func(x: int):
    |     ^^^^
235 |     if not x:
236 |         return 1
    |
help: Add return type annotation: `int`
    |
233 |
    - def func(x: int):
234 + def func(x: int) -> int:
235 |     if not x:
    |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
   --> auto_return_type.py:240:5
    |
240 | def func(x: int):
    |     ^^^^
241 |     if not x:
242 |         return 1
    |
help: Add return type annotation: `int`
    |
239 |
    - def func(x: int):
240 + def func(x: int) -> int:
241 |     if not x:
    |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
   --> auto_return_type.py:248:5
    |
248 | def func():
    |     ^^^^
249 |     try:
250 |         raise ValueError
    |
help: Add return type annotation: `int | None`
    |
247 |
    - def func():
248 + def func() -> int | None:
249 |     try:
    |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
   --> auto_return_type.py:255:5
    |
255 | def func():
    |     ^^^^
256 |     try:
257 |         return 1
    |
help: Add return type annotation: `int | None`
    |
254 |
    - def func():
255 + def func() -> int | None:
256 |     try:
    |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
   --> auto_return_type.py:262:5
    |
262 | def func(x: int):
    |     ^^^^
263 |     for _ in range(3):
264 |         if x > 0:
    |
help: Add return type annotation: `int`
    |
261 |
    - def func(x: int):
262 + def func(x: int) -> int:
263 |     for _ in range(3):
    |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
   --> auto_return_type.py:269:5
    |
269 | def func(x: int):
    |     ^^^^
270 |     if x > 5:
271 |         raise ValueError
    |
help: Add return type annotation: `None`
    |
268 |
    - def func(x: int):
269 + def func(x: int) -> None:
270 |     if x > 5:
    |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
   --> auto_return_type.py:276:5
    |
276 | def func(x: int):
    |     ^^^^
277 |     if x > 5:
278 |         raise ValueError
    |
help: Add return type annotation: `None`
    |
275 |
    - def func(x: int):
276 + def func(x: int) -> None:
277 |     if x > 5:
    |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
   --> auto_return_type.py:283:5
    |
283 | def func(x: int):
    |     ^^^^
284 |     if x > 5:
285 |         raise ValueError
    |
help: Add return type annotation: `int | None`
    |
282 |
    - def func(x: int):
283 + def func(x: int) -> int | None:
284 |     if x > 5:
    |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
   --> auto_return_type.py:290:5
    |
290 | def func():
    |     ^^^^
291 |     try:
292 |         return 5
    |
help: Add return type annotation: `int`
    |
289 |
    - def func():
290 + def func() -> int:
291 |     try:
    |
note: This is an unsafe fix and may change runtime behavior

ANN201 [*] Missing return type annotation for public function `func`
   --> auto_return_type.py:299:5
    |
299 | def func(x: int):
    |     ^^^^
300 |     match x:
301 |         case [1, 2, 3]:
    |
help: Add return type annotation: `str | int`
    |
298 |
    - def func(x: int):
299 + def func(x: int) -> str | int:
300 |     match x:
    |
note: This is an unsafe fix and may change runtime behavior

ANN201 Missing return type annotation for public function `func`
   --> auto_return_type.py:308:5
    |
307 | # Test cases for NotImplementedError - should not get NoReturn auto-fix
308 | def func():
    |     ^^^^
309 |     raise NotImplementedError
    |
help: Add return type annotation

ANN205 Missing return type annotation for staticmethod `func`
   --> auto_return_type.py:314:9
    |
312 | class Class:
313 |     @staticmethod
314 |     def func():
    |         ^^^^
315 |         raise NotImplementedError
    |
help: Add return type annotation

ANN206 Missing return type annotation for classmethod `method`
   --> auto_return_type.py:318:9
    |
317 |     @classmethod
318 |     def method(cls):
    |         ^^^^^^
319 |         raise NotImplementedError
    |
help: Add return type annotation

ANN201 Missing return type annotation for public function `instance_method`
   --> auto_return_type.py:321:9
    |
319 |         raise NotImplementedError
320 |
321 |     def instance_method(self):
    |         ^^^^^^^^^^^^^^^
322 |         raise NotImplementedError
    |
help: Add return type annotation

ANN201 [*] Missing return type annotation for public function `func`
   --> auto_return_type.py:326:5
    |
325 | # Test case: function that raises other exceptions should still get NoReturn
326 | def func():
    |     ^^^^
327 |     raise ValueError
    |
help: Add return type annotation: `Never`
    |
216 |
    - from typing import overload
217 + from typing import overload, Never
218 |
--------------------------------------------------------------------------------
325 | # Test case: function that raises other exceptions should still get NoReturn
    - def func():
326 + def func() -> Never:
327 |     raise ValueError
    |
note: This is an unsafe fix and may change runtime behavior
