diff options
author | Marc Mueller <30130371+cdce8p@users.noreply.github.com> | 2021-10-15 20:53:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-15 20:53:22 +0200 |
commit | 48fbea4656c912e7673e13e050bad6e9e756b5c5 (patch) | |
tree | f642ca3adfd52b5c5c66303df73101a0f3d7463f | |
parent | b1c4735d2897c55e16c5c14b3926ba4b676df8c7 (diff) | |
download | pylint-git-48fbea4656c912e7673e13e050bad6e9e756b5c5.tar.gz |
Use py-version for alternative union syntax check (#5160)
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | pylint/checkers/typecheck.py | 7 | ||||
-rw-r--r-- | pylint/constants.py | 1 | ||||
-rw-r--r-- | tests/functional/a/alternative/alternative_union_syntax.rc | 3 | ||||
-rw-r--r-- | tests/functional/a/alternative/alternative_union_syntax_error.rc | 4 | ||||
-rw-r--r-- | tests/functional/a/alternative/alternative_union_syntax_py37.rc | 4 |
6 files changed, 17 insertions, 5 deletions
@@ -40,6 +40,9 @@ Release date: TBA * Added ``using-f-string-in-unsupported-version`` checker. Issued when ``py-version`` is set to a version that does not support f-strings (< 3.6) +* Use ``py-version`` setting for alternative union syntax check (PEP 604), + instead of the Python interpreter version. + What's New in Pylint 2.11.2? ============================ diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index 68883879d..029f3e7f5 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -95,7 +95,6 @@ from pylint.checkers.utils import ( supports_membership_test, supports_setitem, ) -from pylint.constants import PY310_PLUS from pylint.interfaces import INFERENCE, IAstroidChecker from pylint.utils import get_global_option @@ -896,6 +895,10 @@ accessed. Python regular expressions are accepted.", ), ) + def open(self) -> None: + py_version = get_global_option(self, "py-version") + self._py310_plus = py_version >= (3, 10) + @astroid.decorators.cachedproperty def _suggestion_mode(self): return get_global_option(self, "suggestion-mode", default=True) @@ -1694,7 +1697,7 @@ accessed. Python regular expressions are accepted.", def _detect_unsupported_alternative_union_syntax(self, node: nodes.BinOp) -> None: """Detect if unsupported alternative Union syntax (PEP 604) was used.""" - if PY310_PLUS: # 310+ supports the new syntax + if self._py310_plus: # 310+ supports the new syntax return if isinstance( diff --git a/pylint/constants.py b/pylint/constants.py index 56ce9eaac..05a1a0b25 100644 --- a/pylint/constants.py +++ b/pylint/constants.py @@ -9,7 +9,6 @@ from pylint.__pkginfo__ import __version__ PY38_PLUS = sys.version_info[:2] >= (3, 8) PY39_PLUS = sys.version_info[:2] >= (3, 9) -PY310_PLUS = sys.version_info[:2] >= (3, 10) IS_PYPY = platform.python_implementation() == "PyPy" diff --git a/tests/functional/a/alternative/alternative_union_syntax.rc b/tests/functional/a/alternative/alternative_union_syntax.rc index 68a8c8ef1..595070b48 100644 --- a/tests/functional/a/alternative/alternative_union_syntax.rc +++ b/tests/functional/a/alternative/alternative_union_syntax.rc @@ -1,2 +1,5 @@ +[master] +py-version=3.10 + [testoptions] min_pyver=3.10 diff --git a/tests/functional/a/alternative/alternative_union_syntax_error.rc b/tests/functional/a/alternative/alternative_union_syntax_error.rc index 776b99f68..ca4c715a7 100644 --- a/tests/functional/a/alternative/alternative_union_syntax_error.rc +++ b/tests/functional/a/alternative/alternative_union_syntax_error.rc @@ -1,3 +1,5 @@ +[master] +py-version=3.8 + [testoptions] min_pyver=3.8 -max_pyver=3.10 diff --git a/tests/functional/a/alternative/alternative_union_syntax_py37.rc b/tests/functional/a/alternative/alternative_union_syntax_py37.rc index 776b99f68..ca4c715a7 100644 --- a/tests/functional/a/alternative/alternative_union_syntax_py37.rc +++ b/tests/functional/a/alternative/alternative_union_syntax_py37.rc @@ -1,3 +1,5 @@ +[master] +py-version=3.8 + [testoptions] min_pyver=3.8 -max_pyver=3.10 |