|
1 | 1 | [01m[35m## R1710 (inconsistent-return-statements)[39;49;00m |
2 | | - |
| 2 | +[37m[39;49;00m |
3 | 3 | [01m[35m### :x: Problematic code:[39;49;00m |
4 | 4 | [33m[39;49;00m |
5 | 5 | [33m```[39;49;00m[33mpython[39;49;00m |
6 | | -[34mdef[39;49;00m [32mfoo[39;49;00m(x): |
7 | | - [34mif[39;49;00m x: |
8 | | - [34mreturn[39;49;00m [34m1[39;49;00m |
| 6 | +[34mdef[39;49;00m [32mfoo[39;49;00m(x):[37m[39;49;00m |
| 7 | + [34mif[39;49;00m x:[37m[39;49;00m |
| 8 | + [34mreturn[39;49;00m [34m1[39;49;00m[37m[39;49;00m |
9 | 9 | [33m```[39;49;00m |
10 | | - |
| 10 | +[37m[39;49;00m |
11 | 11 | [01m[35m### :heavy_check_mark: Correct code:[39;49;00m |
12 | 12 | [33m[39;49;00m |
13 | 13 | [33m```[39;49;00m[33mpython[39;49;00m |
14 | | -[34mdef[39;49;00m [32mfoo[39;49;00m(x): |
15 | | - [34mif[39;49;00m x: |
16 | | - [34mreturn[39;49;00m [34m1[39;49;00m |
17 | | - |
18 | | - [34mreturn[39;49;00m [34mNone[39;49;00m |
| 14 | +[34mdef[39;49;00m [32mfoo[39;49;00m(x):[37m[39;49;00m |
| 15 | + [34mif[39;49;00m x:[37m[39;49;00m |
| 16 | + [34mreturn[39;49;00m [34m1[39;49;00m[37m[39;49;00m |
| 17 | +[37m[39;49;00m |
| 18 | + [34mreturn[39;49;00m [34mNone[39;49;00m[37m[39;49;00m |
19 | 19 | [33m```[39;49;00m |
20 | | - |
| 20 | +[37m[39;49;00m |
21 | 21 | [01m[35m### Rationale:[39;49;00m |
22 | | - |
23 | | -Either all [33m`return`[39;49;00m statements in a function should [33m`return`[39;49;00m an expression, |
24 | | -or none of them should. According to **`PEP8`**, if any [33m`return`[39;49;00m statement |
25 | | -returns an expression, any [33m`return`[39;49;00m statements where no value is returned |
26 | | -should explicitly state this as [33m`return None`[39;49;00m, and an explicit [33m`return`[39;49;00m |
27 | | -statement should be present at the end of the function (if reachable). |
28 | | - |
| 22 | +[37m[39;49;00m |
| 23 | +Either all [33m`return`[39;49;00m statements in a function should [33m`return`[39;49;00m an expression, [37m[39;49;00m |
| 24 | +or none of them should. According to **`PEP8`**, if any [33m`return`[39;49;00m statement[37m[39;49;00m |
| 25 | +returns an expression, any [33m`return`[39;49;00m statements where no value is returned[37m[39;49;00m |
| 26 | +should explicitly state this as [33m`return None`[39;49;00m, and an explicit [33m`return`[39;49;00m[37m[39;49;00m |
| 27 | +statement should be present at the end of the function (if reachable).[37m[39;49;00m |
| 28 | +[37m[39;49;00m |
29 | 29 | [01m[35m### Related resources:[39;49;00m |
30 | | - |
31 | | -[34m-[39;49;00m [[94mTestcases[39;49;00m]([36mhttps://github.com/PyCQA/pylint/blob/master/tests/functional/i/inconsistent_returns.py[39;49;00m) |
32 | | -[34m-[39;49;00m [[94mIssue Tracker[39;49;00m]([36mhttps://github.com/PyCQA/pylint/issues?q=is%3Aissue+%22inconsistent-return-statements%22+OR+%22R1710%22[39;49;00m) |
| 30 | +[37m[39;49;00m |
| 31 | +[34m-[39;49;00m[37m [39;49;00m[[94mTestcases[39;49;00m]([36mhttps://github.com/PyCQA/pylint/blob/master/tests/functional/i/inconsistent_returns.py[39;49;00m)[37m[39;49;00m |
| 32 | +[34m-[39;49;00m[37m [39;49;00m[[94mIssue Tracker[39;49;00m]([36mhttps://github.com/PyCQA/pylint/issues?q=is%3Aissue+%22inconsistent-return-statements%22+OR+%22R1710%22[39;49;00m)[37m[39;49;00m |
33 | 33 |
|
0 commit comments