forked from pylint-dev/pylint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip typing.NoReturn tests on Python < 3.6.2
typing.NoReturn was introduced in Python 3.6.2. Move the tests for issue pylint-dev#4122 to a separate file and skip when Python is too old. Co-authored-by: Marc Mueller <[email protected]>
- Loading branch information
Showing
5 changed files
with
62 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
tests/functional/i/inconsistent/inconsistent_returns_noreturn.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""Testing inconsistent returns involving typing.NoReturn annotations.""" | ||
# pylint: disable=missing-docstring, invalid-name | ||
|
||
import sys | ||
import typing | ||
|
||
def parser_error(msg) -> typing.NoReturn: # pylint: disable=unused-argument | ||
sys.exit(1) | ||
|
||
def parser_error_nortype(msg): # pylint: disable=unused-argument | ||
sys.exit(2) | ||
|
||
|
||
from typing import NoReturn # pylint: disable=wrong-import-position | ||
|
||
def parser_error_name(msg) -> NoReturn: # pylint: disable=unused-argument | ||
sys.exit(3) | ||
|
||
def bug_pylint_4122(s): | ||
""" | ||
Every returns is consistent because parser_error has type hints | ||
indicating it never returns | ||
""" | ||
try: | ||
n = int(s) | ||
if n < 1: | ||
raise ValueError() | ||
return n | ||
except ValueError: | ||
parser_error('parser error') | ||
|
||
def bug_pylint_4122_wrong(s): # [inconsistent-return-statements] | ||
""" | ||
Every returns is not consistent because parser_error_nortype has no type hints | ||
""" | ||
try: | ||
n = int(s) | ||
if n < 1: | ||
raise ValueError() | ||
return n | ||
except ValueError: | ||
parser_error_nortype('parser error') | ||
|
||
def bug_pylint_4122_bis(s): | ||
""" | ||
Every returns is consistent because parser_error has type hints | ||
indicating it never returns | ||
""" | ||
try: | ||
n = int(s) | ||
if n < 1: | ||
raise ValueError() | ||
return n | ||
except ValueError: | ||
parser_error_name('parser error') |
5 changes: 5 additions & 0 deletions
5
tests/functional/i/inconsistent/inconsistent_returns_noreturn.rc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[testoptions] | ||
min_pyver=3.6.2 | ||
|
||
[REFACTORING] | ||
never-returning-functions=sys.exit,sys.getdefaultencoding |
1 change: 1 addition & 0 deletions
1
tests/functional/i/inconsistent/inconsistent_returns_noreturn.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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. |