-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issues with Python 3.6.0 (#4446)
* tox: Enable testing python 3.6.0 The requirements_test.txt includes black, pre-commit, and pyupgrade which are not compatible with Python 3.6.0. Add python_full_version markers so that `tox -e py36` works with 3.6.0. * Fix typing.Counter import for Python 3.6.0 typing.Counter was added in Python 3.6.1. In the strings checker, guard the import with TYPE_CHECKING and use a type annotation comment to fix usage with Python 3.6.0. * 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. * Update ChangeLog and whatsnew
- Loading branch information
Showing
10 changed files
with
77 additions
and
60 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
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
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
autoflake==1.4 | ||
black==21.5b1 | ||
black==21.5b1;python_full_version>="3.6.2" | ||
flake8==3.9.2 | ||
isort==5.8.0 | ||
mypy==0.812 | ||
pyupgrade==2.15.0 | ||
pyupgrade==2.15.0;python_full_version>="3.6.1" | ||
black-disable-checker==1.0.1 |
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. |