Skip to content

Commit 840a95d

Browse files
Add unsupported version checks for Python 3.8+ syntax
walrus operator #9820 positional-only args #9823
1 parent 2d484f5 commit 840a95d

27 files changed

+151
-48
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import random
2+
3+
# +1 : [using-assignment-expression-in-unsupported-version]
4+
if zero_or_one := random.randint(0, 1):
5+
assert zero_or_one == 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The assignment expression (walrus) operator (`:=`) was introduced in Python 3.8; to use it, please use a more recent version of Python.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import random
2+
3+
zero_or_one = random.randint(0, 1)
4+
if zero_or_one:
5+
assert zero_or_one == 1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[main]
2+
py-version=3.7
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def add(x, y, /): # [using-positional-only-args-in-unsupported-version]
2+
return x + y
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Positional-only arguments were introduced in Python 3.8; to use them, please use a more recent version of Python.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# pylint: disable=missing-function-docstring, missing-module-docstring
2+
def add(x, y):
3+
return x + y
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[main]
2+
py-version=3.7

doc/user_guide/checkers/features.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,9 @@ Verbatim name of the checker is ``unsupported_version``.
13511351

13521352
Unsupported Version checker Messages
13531353
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1354+
:using-assignment-expression-in-unsupported-version (W2605): *Assignment expression is not supported by all versions included in the py-version setting*
1355+
Used when the py-version set by the user is lower than 3.8 and pylint
1356+
encounters an assignment expression (walrus) operator.
13541357
:using-exception-groups-in-unsupported-version (W2603): *Exception groups are not supported by all versions included in the py-version setting*
13551358
Used when the py-version set by the user is lower than 3.11 and pylint
13561359
encounters ``except*`` or `ExceptionGroup``.
@@ -1360,6 +1363,9 @@ Unsupported Version checker Messages
13601363
:using-generic-type-syntax-in-unsupported-version (W2604): *Generic type syntax (PEP 695) is not supported by all versions included in the py-version setting*
13611364
Used when the py-version set by the user is lower than 3.12 and pylint
13621365
encounters generic type syntax.
1366+
:using-positional-only-args-in-unsupported-version (W2606): *Positional-only arguments are not supported by all versions included in the py-version setting*
1367+
Used when the py-version set by the user is lower than 3.8 and pylint
1368+
encounters positional-only arguments.
13631369
:using-final-decorator-in-unsupported-version (W2602): *typing.final is not supported by all versions included in the py-version setting*
13641370
Used when the py-version set by the user is lower than 3.8 and pylint
13651371
encounters a ``typing.final`` decorator.

doc/user_guide/messages/messages_overview.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,13 @@ All messages in the warning category:
348348
warning/useless-parent-delegation
349349
warning/useless-type-doc
350350
warning/useless-with-lock
351+
warning/using-assignment-expression-in-unsupported-version
351352
warning/using-constant-test
352353
warning/using-exception-groups-in-unsupported-version
353354
warning/using-f-string-in-unsupported-version
354355
warning/using-final-decorator-in-unsupported-version
355356
warning/using-generic-type-syntax-in-unsupported-version
357+
warning/using-positional-only-args-in-unsupported-version
356358
warning/while-used
357359
warning/wildcard-import
358360
warning/wrong-exception-operation

0 commit comments

Comments
 (0)