Description
This is an umbrella issue to collect all the syntax errors that are raised by the CPython compiler. These are different than the ones that are raised by the parser. IOW, the source code which raises these errors are valid as per the grammar.
- Duplicate parameter names ([syntax-errors] Make duplicate parameter names a semantic error #17131)
-
await
outside async function (PLE1142) ([syntax-errors]await
outside async functions #17363) -
yield
outside function (F704) ([syntax-errors]yield
,yield from
, andawait
outside functions #17298) -
return
outside function (F706) ([syntax-errors]return
outside function #17300) -
await
in annotations (extending theyield
and named expression handling from [syntax-errors] Invalid syntax in annotations #17101) ([syntax-errors] Extend annotation checks toawait
#17282) - PEP 649 annotations in annotated assignments ([syntax-errors] Check annotations in annotated assignments #17283)
- Ruff fails to reject invalid syntax in annotation scopes #11118 ([syntax-errors] Invalid syntax in annotations #17101)
- Duplicate key in mapping
match
pattern (case {"x": 1, "x": 2}:
) ([syntax-errors] Detect duplicate keys inmatch
mapping patterns #17129) - Name assigned before
global
declaration (PLE0118) ([syntax-errors] Reimplement PLE0118 #17135) - Flag starred expressions in
return
andyield
#16520 ([syntax-errors] Starred expressions in return, yield, and for #17134) - Ruff doesn't raise syntax error for single starred assignment target #13759 (cpython#100581)
- Multiple assignments to name 'a' in pattern (
case [a, b, a]:
) - Irrefutable patterns are syntax errors
SyntaxError: name capture 'x' makes remaining patterns unreachable
SyntaxError: wildcard makes remaining patterns unreachable
- Ruff fails to detect duplicate type parameter names #11119
- No syntax error for
[(a := ...) for a in b]
#14395
A lot of them are mentioned in this comment. These all would be part of E999
rule.
Version-related errors
The following are both version-related and detected by the compiler. Many of them were originally tracked in #6591.
3.13
-
(cpython#111123) ([syntax-errors] Document behavior ofglobal
declarations intry
nodesglobal
declarations intry
nodes before 3.13 #17285)- Are now allowed in
except
blocks if the variable is only referenced in anelse
block - Are now disallowed in
else
blocks if the variable is only referenced in anexcept
block
- Are now allowed in
3.11
- Async comprehensions are now allowed when nested inside sync comprehensions in async functions (cpython#77527) ([syntax-errors] Async comprehension in sync comprehension #17177)
3.10
-
del __debug__
is a syntax error on Python 3.10+ (cpython#89163)