-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
0 / 10 of 1 issue completedClosed
0 / 10 of 1 issue completed
Copy link
Labels
parserRelated to the parserRelated to the parserruleImplementing or modifying a lint ruleImplementing or modifying a lint rule
Description
Our parser doesn't take into account the Python version aka target-version
setting while parsing the source code. This means that we would allow having a match statement when the target Python version is 3.9 or lower. We want to signal this to the user.
One solution is to provide a diagnostic after the parsing is done. This diagnostic would indicate to the user that there's a syntax usage which isn't valid for the current target version. This is what's being done in Rome and Pyright1. We would still continue linting the file and emit other diagnostics as well.
Following is a non-exhaustive list of syntax changes with the minimum required Python version:
3.13
- Type defaults for type parameters (PEP 696) ([syntax-errors] Type parameter defaults before Python 3.13 #16447)
3.12
- Formalized grammar for f-strings (PEP 701) ([syntax-errors] PEP 701 f-strings before Python 3.12 #16543)
-
type
statements ([syntax-errors]type
statements before Python 3.12 #16478) -
type
parameter lists ([syntax-errors] Type parameter lists before Python 3.12 #16479)
3.11
-
except*
syntax ([syntax-errors]except*
before Python 3.11 #16446) - Star expressions are allowed in index operations via PEP 646 ([syntax-errors] Star expression in index before Python 3.11 #16544)
- Star expressions are allowed in annotations for
*args
via PEP 646 ([syntax-errors] Star annotations before Python 3.11 #16545)
3.10
3.9
- Relaxing grammar restrictions on decorators (PEP 614) ([syntax-errors] Named expressions in decorators before Python 3.9 #16386)
- Parenthesized context managers (formally made part of the language spec in Python 3.10, but usable -- and commonly used -- in Python >=3.9) ([syntax-errors] Parenthesized context managers before Python 3.9 #16523)
- Starred unpacking expressions are allowed in
for
statements on Python 3.9+ (officially made part of the language spec in Python 3.11) (cpython#90881) ([syntax-errors] Tuple unpacking infor
statement iterator clause before Python 3.9 #16558) - Assignment expressions can now be used unparenthesized in sequence indexes (but not slices) (What’s New In Python 3.10 ([syntax-errors] Unparenthesized assignment expressions in sets and indexes #16404))
- These also worked on 3.9 when testing manually
3.8
- Assignment expressions (PEP 572) (Detect assignment expressions before Python 3.8 #16383)
- Positional-only parameters (PEP 570) ([syntax-errors] Positional-only parameters before Python 3.8 #16481)
- Parenthesized keyword-argument calls (e.g.
f((a)=1)
) are no longer allowed on Python 3.8+ (cpython#78822) ([syntax-errors] Parenthesized keyword argument names after Python 3.8 #16482) - Iterable unpacking in
return
andyield
statements no longer needs to be parenthesized on Pythonn 3.8+ (cpython#76298) ([syntax-errors] Tuple unpacking inreturn
andyield
before Python 3.8 #16485)
Footnotes
-
Pyright: Type alias statement requires Python 3.12 or newer
↩
bschoenmaeckers, td-anne, R1kaB3rN, Avasam, tueda and 3 morezaniebachimnol
Sub-issues
Metadata
Metadata
Assignees
Labels
parserRelated to the parserRelated to the parserruleImplementing or modifying a lint ruleImplementing or modifying a lint rule