Skip to content

Commit d281f2f

Browse files
Pierre-Sassoulasjnsnow
andauthoredJun 28, 2024··
[unreachable-code] Fix the false positive in python 3.8 (#9753)
Refs #9751 Co-authored-by: John Snow <jsnow@redhat.com>
1 parent d8f84b0 commit d281f2f

File tree

6 files changed

+51
-18
lines changed

6 files changed

+51
-18
lines changed
 

‎doc/whatsnew/fragments/9751.bugfix

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fixed a false positive ``unreachable-code`` when using ``typing.Any`` as return type in python
2+
3.8, the ``typing.NoReturn`` are not taken into account anymore for python 3.8 however.
3+
4+
Closes #9751

‎pylint/checkers/utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2184,7 +2184,9 @@ def is_terminating_func(node: nodes.Call) -> bool:
21842184
*TYPING_NEVER,
21852185
*TYPING_NORETURN,
21862186
# In Python 3.7 - 3.8, NoReturn is alias of '_SpecialForm'
2187-
"typing._SpecialForm",
2187+
# "typing._SpecialForm",
2188+
# But 'typing.Any' also inherits _SpecialForm
2189+
# See #9751
21882190
)
21892191
):
21902192
return True
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
pylint 3.2.4 regression
3+
https://github.com/pylint-dev/pylint/issues/9751
4+
"""
5+
6+
# pylint: disable=missing-function-docstring
7+
8+
from typing import Any
9+
10+
def repro() -> Any:
11+
return 5
12+
13+
def main():
14+
x = repro() + 5
15+
print(x)

‎tests/functional/u/used/used_before_assignment.py

+1-17
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# pylint: disable=consider-using-f-string, missing-function-docstring
33
import datetime
44
import sys
5-
from typing import NoReturn
5+
# from typing import NoReturn # uncomment when we reunite with used_before_assignment_py38.py
66

77
MSG = "hello %s" % MSG # [used-before-assignment]
88

@@ -206,19 +206,3 @@ def inner_if_continues_outer_if_has_no_other_statements():
206206
else:
207207
order = None
208208
print(order)
209-
210-
211-
class PlatformChecks:
212-
"""https://github.com/pylint-dev/pylint/issues/9674"""
213-
def skip(self, msg) -> NoReturn:
214-
raise Exception(msg) # pylint: disable=broad-exception-raised
215-
216-
def print_platform_specific_command(self):
217-
if sys.platform == "linux":
218-
cmd = "ls"
219-
elif sys.platform == "win32":
220-
cmd = "dir"
221-
else:
222-
self.skip("only runs on Linux/Windows")
223-
224-
print(cmd)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Temporary file until we drop python 3.8
3+
See https://github.com/pylint-dev/pylint/issues/9751
4+
Please reunite with used_before_assignment.py at this point
5+
"""
6+
7+
# pylint: disable=missing-docstring
8+
9+
import sys
10+
from typing import NoReturn
11+
12+
13+
class PlatformChecks:
14+
"""https://github.com/pylint-dev/pylint/issues/9674"""
15+
def skip(self, msg) -> NoReturn:
16+
raise Exception(msg) # pylint: disable=broad-exception-raised
17+
18+
def print_platform_specific_command(self):
19+
if sys.platform == "linux":
20+
cmd = "ls"
21+
elif sys.platform == "win32":
22+
cmd = "dir"
23+
else:
24+
self.skip("only runs on Linux/Windows")
25+
26+
print(cmd)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[testoptions]
2+
min_pyver=3.9

0 commit comments

Comments
 (0)
Please sign in to comment.