Skip to content

Commit 815c40b

Browse files
committed
Skip typing.NoReturn tests on Python < 3.6.2
typing.NoReturn was introduced in Python 3.6.2. Move the tests for issue #4122 to a separate file and skip when Python is too old.
1 parent 5ead29c commit 815c40b

5 files changed

+62
-55
lines changed

tests/functional/i/inconsistent/inconsistent_returns.py

-53
Original file line numberDiff line numberDiff line change
@@ -336,59 +336,6 @@ def bug_pylint_3873_2():
336336
nothing_to_do()
337337
return False
338338

339-
import typing # pylint: disable=wrong-import-position
340-
341-
def parser_error(msg) -> typing.NoReturn: #pylint:disable=unused-argument
342-
sys.exit(1)
343-
344-
def parser_error_nortype(msg): #pylint:disable=unused-argument
345-
sys.exit(2)
346-
347-
348-
from typing import NoReturn # pylint: disable=wrong-import-position
349-
350-
def parser_error_name(msg) -> NoReturn: #pylint:disable=unused-argument
351-
sys.exit(3)
352-
353-
def bug_pylint_4122(s):
354-
"""
355-
Every returns is consistent because parser_error has type hints
356-
indicating it never returns
357-
"""
358-
try:
359-
n = int(s)
360-
if n < 1:
361-
raise ValueError()
362-
return n
363-
except ValueError:
364-
parser_error('parser error')
365-
366-
def bug_pylint_4122_wrong(s): # [inconsistent-return-statements]
367-
"""
368-
Every returns is not consistent because parser_error_nortype has no type hints
369-
"""
370-
try:
371-
n = int(s)
372-
if n < 1:
373-
raise ValueError()
374-
return n
375-
except ValueError:
376-
parser_error_nortype('parser error')
377-
378-
def bug_pylint_4122_bis(s):
379-
"""
380-
Every returns is consistent because parser_error has type hints
381-
indicating it never returns
382-
"""
383-
try:
384-
n = int(s)
385-
if n < 1:
386-
raise ValueError()
387-
return n
388-
except ValueError:
389-
parser_error_name('parser error')
390-
391-
392339
# https://github.com/PyCQA/pylint/issues/4019
393340
def bug_pylint_4019(x):
394341
"""

tests/functional/i/inconsistent/inconsistent_returns.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ inconsistent-return-statements:262:8:bug_1794_inner_func_in_if_counter_example_3
1414
inconsistent-return-statements:267:0:bug_3468:Either all return statements in a function should return an expression, or none of them should.
1515
inconsistent-return-statements:277:0:bug_3468_variant:Either all return statements in a function should return an expression, or none of them should.
1616
inconsistent-return-statements:322:0:bug_pylint_3873_1:Either all return statements in a function should return an expression, or none of them should.
17-
inconsistent-return-statements:366:0:bug_pylint_4122_wrong:Either all return statements in a function should return an expression, or none of them should.
18-
inconsistent-return-statements:402:0:bug_pylint_4019_wrong:Either all return statements in a function should return an expression, or none of them should.
17+
inconsistent-return-statements:349:0:bug_pylint_4019_wrong:Either all return statements in a function should return an expression, or none of them should.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#pylint: disable=missing-docstring, invalid-name
2+
"""Testing inconsistent returns involving typing.NoReturn annotations."""
3+
4+
import sys
5+
import typing
6+
7+
def parser_error(msg) -> typing.NoReturn: #pylint:disable=unused-argument
8+
sys.exit(1)
9+
10+
def parser_error_nortype(msg): #pylint:disable=unused-argument
11+
sys.exit(2)
12+
13+
14+
from typing import NoReturn # pylint: disable=wrong-import-position
15+
16+
def parser_error_name(msg) -> NoReturn: #pylint:disable=unused-argument
17+
sys.exit(3)
18+
19+
def bug_pylint_4122(s):
20+
"""
21+
Every returns is consistent because parser_error has type hints
22+
indicating it never returns
23+
"""
24+
try:
25+
n = int(s)
26+
if n < 1:
27+
raise ValueError()
28+
return n
29+
except ValueError:
30+
parser_error('parser error')
31+
32+
def bug_pylint_4122_wrong(s): # [inconsistent-return-statements]
33+
"""
34+
Every returns is not consistent because parser_error_nortype has no type hints
35+
"""
36+
try:
37+
n = int(s)
38+
if n < 1:
39+
raise ValueError()
40+
return n
41+
except ValueError:
42+
parser_error_nortype('parser error')
43+
44+
def bug_pylint_4122_bis(s):
45+
"""
46+
Every returns is consistent because parser_error has type hints
47+
indicating it never returns
48+
"""
49+
try:
50+
n = int(s)
51+
if n < 1:
52+
raise ValueError()
53+
return n
54+
except ValueError:
55+
parser_error_name('parser error')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[testoptions]
2+
min_pyver=3.6.2
3+
4+
[REFACTORING]
5+
never-returning-functions=sys.exit,sys.getdefaultencoding
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
inconsistent-return-statements:32:0:bug_pylint_4122_wrong:Either all return statements in a function should return an expression, or none of them should.

0 commit comments

Comments
 (0)