From 644b3ba44a2b05e3986f159de93a6b5dfee45c1e Mon Sep 17 00:00:00 2001 From: Peter Kolbus Date: Thu, 6 May 2021 08:21:56 -0500 Subject: [PATCH] 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. Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> --- .../i/inconsistent/inconsistent_returns.py | 53 ------------------ .../i/inconsistent/inconsistent_returns.txt | 3 +- .../inconsistent_returns_noreturn.py | 55 +++++++++++++++++++ .../inconsistent_returns_noreturn.rc | 5 ++ .../inconsistent_returns_noreturn.txt | 1 + 5 files changed, 62 insertions(+), 55 deletions(-) create mode 100644 tests/functional/i/inconsistent/inconsistent_returns_noreturn.py create mode 100644 tests/functional/i/inconsistent/inconsistent_returns_noreturn.rc create mode 100644 tests/functional/i/inconsistent/inconsistent_returns_noreturn.txt diff --git a/tests/functional/i/inconsistent/inconsistent_returns.py b/tests/functional/i/inconsistent/inconsistent_returns.py index cc8458e6a8..08dde253e9 100644 --- a/tests/functional/i/inconsistent/inconsistent_returns.py +++ b/tests/functional/i/inconsistent/inconsistent_returns.py @@ -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): """ diff --git a/tests/functional/i/inconsistent/inconsistent_returns.txt b/tests/functional/i/inconsistent/inconsistent_returns.txt index 749797f91e..d0a6dd1338 100644 --- a/tests/functional/i/inconsistent/inconsistent_returns.txt +++ b/tests/functional/i/inconsistent/inconsistent_returns.txt @@ -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. diff --git a/tests/functional/i/inconsistent/inconsistent_returns_noreturn.py b/tests/functional/i/inconsistent/inconsistent_returns_noreturn.py new file mode 100644 index 0000000000..768d6e6585 --- /dev/null +++ b/tests/functional/i/inconsistent/inconsistent_returns_noreturn.py @@ -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') diff --git a/tests/functional/i/inconsistent/inconsistent_returns_noreturn.rc b/tests/functional/i/inconsistent/inconsistent_returns_noreturn.rc new file mode 100644 index 0000000000..bf9569ba24 --- /dev/null +++ b/tests/functional/i/inconsistent/inconsistent_returns_noreturn.rc @@ -0,0 +1,5 @@ +[testoptions] +min_pyver=3.6.2 + +[REFACTORING] +never-returning-functions=sys.exit,sys.getdefaultencoding diff --git a/tests/functional/i/inconsistent/inconsistent_returns_noreturn.txt b/tests/functional/i/inconsistent/inconsistent_returns_noreturn.txt new file mode 100644 index 0000000000..9b23552d19 --- /dev/null +++ b/tests/functional/i/inconsistent/inconsistent_returns_noreturn.txt @@ -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.