Skip to content

Commit

Permalink
Skip typing.NoReturn tests on Python < 3.6.2
Browse files Browse the repository at this point in the history
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
pkolbus and cdce8p committed May 12, 2021
1 parent 419c91f commit 644b3ba
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 55 deletions.
53 changes: 0 additions & 53 deletions tests/functional/i/inconsistent/inconsistent_returns.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,59 +336,6 @@ def bug_pylint_3873_2():
nothing_to_do()
return False

import typing # pylint: disable=wrong-import-position

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')


# https://github.com/PyCQA/pylint/issues/4019
def bug_pylint_4019(x):
"""
Expand Down
3 changes: 1 addition & 2 deletions tests/functional/i/inconsistent/inconsistent_returns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ inconsistent-return-statements:262:8:bug_1794_inner_func_in_if_counter_example_3
inconsistent-return-statements:267:0:bug_3468:Either all return statements in a function should return an expression, or none of them should.
inconsistent-return-statements:277:0:bug_3468_variant:Either all return statements in a function should return an expression, or none of them should.
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.
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.
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.
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.
55 changes: 55 additions & 0 deletions tests/functional/i/inconsistent/inconsistent_returns_noreturn.py
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')
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
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.

0 comments on commit 644b3ba

Please sign in to comment.