Skip to content

Commit 48fbea4

Browse files
authored
Use py-version for alternative union syntax check (#5160)
1 parent b1c4735 commit 48fbea4

File tree

6 files changed

+17
-5
lines changed

6 files changed

+17
-5
lines changed

ChangeLog

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ Release date: TBA
4040
* Added ``using-f-string-in-unsupported-version`` checker. Issued when ``py-version``
4141
is set to a version that does not support f-strings (< 3.6)
4242

43+
* Use ``py-version`` setting for alternative union syntax check (PEP 604),
44+
instead of the Python interpreter version.
45+
4346

4447
What's New in Pylint 2.11.2?
4548
============================

pylint/checkers/typecheck.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
supports_membership_test,
9696
supports_setitem,
9797
)
98-
from pylint.constants import PY310_PLUS
9998
from pylint.interfaces import INFERENCE, IAstroidChecker
10099
from pylint.utils import get_global_option
101100

@@ -896,6 +895,10 @@ class should be ignored. A mixin class is detected if its name ends with \
896895
),
897896
)
898897

898+
def open(self) -> None:
899+
py_version = get_global_option(self, "py-version")
900+
self._py310_plus = py_version >= (3, 10)
901+
899902
@astroid.decorators.cachedproperty
900903
def _suggestion_mode(self):
901904
return get_global_option(self, "suggestion-mode", default=True)
@@ -1694,7 +1697,7 @@ def visit_binop(self, node: nodes.BinOp) -> None:
16941697

16951698
def _detect_unsupported_alternative_union_syntax(self, node: nodes.BinOp) -> None:
16961699
"""Detect if unsupported alternative Union syntax (PEP 604) was used."""
1697-
if PY310_PLUS: # 310+ supports the new syntax
1700+
if self._py310_plus: # 310+ supports the new syntax
16981701
return
16991702

17001703
if isinstance(

pylint/constants.py

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
PY38_PLUS = sys.version_info[:2] >= (3, 8)
1111
PY39_PLUS = sys.version_info[:2] >= (3, 9)
12-
PY310_PLUS = sys.version_info[:2] >= (3, 10)
1312

1413
IS_PYPY = platform.python_implementation() == "PyPy"
1514

Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
[master]
2+
py-version=3.10
3+
14
[testoptions]
25
min_pyver=3.10

tests/functional/a/alternative/alternative_union_syntax_error.rc

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[master]
2+
py-version=3.8
3+
14
[testoptions]
25
min_pyver=3.8
3-
max_pyver=3.10

tests/functional/a/alternative/alternative_union_syntax_py37.rc

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[master]
2+
py-version=3.8
3+
14
[testoptions]
25
min_pyver=3.8
3-
max_pyver=3.10

0 commit comments

Comments
 (0)