---
source: crates/ruff_linter/src/rules/flake8_return/mod.rs
---
RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
  --> RET503.py:20:1
   |
19 |   # if/elif/else
20 | / def x(y):
21 | |     if not y:
22 | |         return 1
   | |________________^
23 |       # error
   |
help: Add explicit `return` statement
   |
22 |         return 1
23 +     return None
24 |     # error
   |
note: This is an unsafe fix and may change runtime behavior

RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
  --> RET503.py:26:1
   |
26 | / def x(y):
27 | |     if not y:
28 | |         print()  # error
29 | |     else:
30 | |         return 2
   | |________________^
   |
help: Add explicit `return` statement
   |
30 |         return 2
31 +     return None
32 |
   |
note: This is an unsafe fix and may change runtime behavior

RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
  --> RET503.py:33:1
   |
33 | / def x(y):
34 | |     if not y:
35 | |         return 1
36 | |
37 | |     print()  # error
   | |___________^
   |
help: Add explicit `return` statement
   |
37 |     print()  # error
38 +     return None
39 |
   |
note: This is an unsafe fix and may change runtime behavior

RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
  --> RET503.py:41:1
   |
40 |   # for
41 | / def x(y):
42 | |     for i in range(10):
43 | |         if i > 10:
44 | |             return i
   | |____________________^
45 |       # error
   |
help: Add explicit `return` statement
   |
44 |             return i
45 +     return None
46 |     # error
   |
note: This is an unsafe fix and may change runtime behavior

RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
  --> RET503.py:48:1
   |
48 | / def x(y):
49 | |     for i in range(10):
50 | |         if i > 10:
51 | |             return i
52 | |     else:
53 | |         print()  # error
   | |_______________^
   |
help: Add explicit `return` statement
   |
53 |         print()  # error
54 +     return None
55 |
   |
note: This is an unsafe fix and may change runtime behavior

RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
  --> RET503.py:57:1
   |
56 |   # A nonexistent function
57 | / def func_unknown(x):
58 | |     if x > 0:
59 | |         return False
60 | |     no_such_function()  # error
   | |______________________^
   |
help: Add explicit `return` statement
   |
60 |     no_such_function()  # error
61 +     return None
62 |
   |
note: This is an unsafe fix and may change runtime behavior

RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
  --> RET503.py:64:1
   |
63 |   # A function that does return the control
64 | / def func_no_noreturn(x):
65 | |     if x > 0:
66 | |         return False
67 | |     print("", end="")  # error
   | |_____________________^
   |
help: Add explicit `return` statement
   |
67 |     print("", end="")  # error
68 +     return None
69 |
   |
note: This is an unsafe fix and may change runtime behavior

RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
  --> RET503.py:82:1
   |
81 |   # last line in while loop
82 | / def x(y):
83 | |     while i > 0:
84 | |         if y > 0:
85 | |             return 1
86 | |         y += 1
   | |______________^
   |
help: Add explicit `return` statement
   |
86 |         y += 1
87 +     return None
88 |
   |
note: This is an unsafe fix and may change runtime behavior

RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
   --> RET503.py:113:1
    |
112 |   # return value within loop
113 | / def bar1(x, y, z):
114 | |     for i in x:
115 | |         if i > y:
116 | |             break
117 | |         return z
    | |________________^
    |
help: Add explicit `return` statement
    |
117 |         return z
118 +     return None
119 |
    |
note: This is an unsafe fix and may change runtime behavior

RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
   --> RET503.py:120:1
    |
120 | / def bar3(x, y, z):
121 | |     for i in x:
122 | |         if i > y:
123 | |             if z:
124 | |                 break
125 | |         else:
126 | |             return z
127 | |         return None
    | |___________________^
    |
help: Add explicit `return` statement
    |
127 |         return None
128 +     return None
129 |
    |
note: This is an unsafe fix and may change runtime behavior

RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
   --> RET503.py:130:1
    |
130 | / def bar1(x, y, z):
131 | |     for i in x:
132 | |         if i < y:
133 | |             continue
134 | |         return z
    | |________________^
    |
help: Add explicit `return` statement
    |
134 |         return z
135 +     return None
136 |
    |
note: This is an unsafe fix and may change runtime behavior

RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
   --> RET503.py:137:1
    |
137 | / def bar3(x, y, z):
138 | |     for i in x:
139 | |         if i < y:
140 | |             if z:
141 | |                 continue
142 | |         else:
143 | |             return z
144 | |         return None
    | |___________________^
    |
help: Add explicit `return` statement
    |
144 |         return None
145 +     return None
146 |
    |
note: This is an unsafe fix and may change runtime behavior

RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
   --> RET503.py:271:1
    |
271 | / def nested(values):
272 | |     if not values:
273 | |         return False
274 | |
275 | |     for value in values:
276 | |         print(value)
    | |____________________^
    |
help: Add explicit `return` statement
    |
276 |         print(value)
277 +     return None
278 |
    |
note: This is an unsafe fix and may change runtime behavior

RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
   --> RET503.py:287:1
    |
286 |   # match
287 | / def x(y):
288 | |     match y:
289 | |         case 0:
290 | |             return 1
291 | |         case 1:
292 | |             print()  # error
    | |___________________^
    |
help: Add explicit `return` statement
    |
292 |             print()  # error
293 +     return None
294 |
    |
note: This is an unsafe fix and may change runtime behavior

RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
   --> RET503.py:300:5
    |
299 |   def end_of_statement():
300 | /     def example():
301 | |         if True:
302 | |             return ""
    | |_____________________^
    |
help: Add explicit `return` statement
    |
302 |             return ""
303 +         return None
304 |
    |
note: This is an unsafe fix and may change runtime behavior

RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
   --> RET503.py:305:5
    |
305 | /     def example():
306 | |         if True:
307 | |             return ""
    | |_____________________^
    |
help: Add explicit `return` statement
    |
307 |             return ""
308 +         return None
309 |
    |
note: This is an unsafe fix and may change runtime behavior

RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
   --> RET503.py:310:5
    |
310 | /     def example():
311 | |         if True:
312 | |             return ""  # type: ignore
    | |_____________________^
    |
help: Add explicit `return` statement
    |
312 |             return ""  # type: ignore
313 +         return None
314 |
    |
note: This is an unsafe fix and may change runtime behavior

RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
   --> RET503.py:315:5
    |
315 | /     def example():
316 | |         if True:
317 | |             return ""  ;
    | |_____________________^
    |
help: Add explicit `return` statement
    |
317 |             return ""  ;
318 +         return None
319 |
    |
note: This is an unsafe fix and may change runtime behavior

RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
   --> RET503.py:320:5
    |
320 | /     def example():
321 | |         if True:
322 | |             return "" \
    | |_____________________^
323 |                   ;  # type: ignore
    |
help: Add explicit `return` statement
    |
323 |                 ;  # type: ignore
324 +         return None
325 |
    |
note: This is an unsafe fix and may change runtime behavior

RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
   --> RET503.py:326:1
    |
326 | / def end_of_file():
327 | |     if False:
328 | |         return 1
329 | |     x = 2 \
    | |_________^
    |
help: Add explicit `return` statement
    |
330 |
331 +     return None
332 |
    |
note: This is an unsafe fix and may change runtime behavior

RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
   --> RET503.py:398:1
    |
398 | / def f():
399 | |     if a:
400 | |         return b
401 | |     else:
402 | |         with c:
403 | |             d
    | |_____________^
    |
help: Add explicit `return` statement
    |
403 |             d
404 +     return None
405 |
    |
note: This is an unsafe fix and may change runtime behavior

RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
   --> RET503.py:413:1
    |
411 |   # the semantic model hasn't yet seen `bar`'s declaration.
412 |   # Supporting nested functions requires making this a deferred rule.
413 | / def foo(x: int) -> int:
414 | |     def bar() -> NoReturn:
415 | |         abort()
416 | |     if x == 5:
417 | |         return 5
418 | |     bar()
    | |_________^
    |
help: Add explicit `return` statement
    |
417 |         return 5
    -     bar()
418 +     bar()
419 +     return None
    |
note: This is an unsafe fix and may change runtime behavior
