pub enum UnsupportedSyntaxErrorKind {
Show 18 variants
Match,
Walrus,
ExceptStar,
UnparenthesizedNamedExpr(UnparenthesizedNamedExprKind),
ParenthesizedKeywordArgumentName,
StarTuple(StarTupleKind),
RelaxedDecorator(RelaxedDecoratorError),
PositionalOnlyParameter,
TypeParameterList,
TypeAliasStatement,
TypeParamDefault,
Pep701FString(FStringKind),
ParenthesizedContextManager,
StarExpressionInIndex,
StarAnnotation,
UnparenthesizedUnpackInFor,
UnparenthesizedExceptionTypes,
TemplateStrings,
}Variants§
Match
Walrus
ExceptStar
UnparenthesizedNamedExpr(UnparenthesizedNamedExprKind)
Represents the use of an unparenthesized named expression (:=) in a set literal, set
comprehension, or sequence index before Python 3.10.
§Examples
These are allowed on Python 3.10:
{x := 1, 2, 3} # set literal
{last := x for x in range(3)} # set comprehension
lst[x := 1] # sequence indexBut on Python 3.9 the named expression needs to be parenthesized:
{(x := 1), 2, 3} # set literal
{(last := x) for x in range(3)} # set comprehension
lst[(x := 1)] # sequence indexHowever, unparenthesized named expressions are never allowed in slices:
lst[x:=1:-1] # syntax error
lst[1:x:=1] # syntax error
lst[1:3:x:=1] # syntax error
lst[(x:=1):-1] # ok
lst[1:(x:=1)] # ok
lst[1:3:(x:=1)] # ok§References
ParenthesizedKeywordArgumentName
Represents the use of a parenthesized keyword argument name after Python 3.8.
§Example
From BPO 34641 it sounds like this was only accidentally supported and was removed when noticed. Code like this used to be valid:
f((a)=1)After Python 3.8, you have to omit the parentheses around a:
f(a=1)StarTuple(StarTupleKind)
Represents the use of unparenthesized tuple unpacking in a return statement or yield
expression before Python 3.8.
§Examples
Before Python 3.8, this syntax was allowed:
rest = (4, 5, 6)
def f():
t = 1, 2, 3, *rest
return t
def g():
t = 1, 2, 3, *rest
yield tBut this was not:
rest = (4, 5, 6)
def f():
return 1, 2, 3, *rest
def g():
yield 1, 2, 3, *restInstead, parentheses were required in the return and yield cases:
rest = (4, 5, 6)
def f():
return (1, 2, 3, *rest)
def g():
yield (1, 2, 3, *rest)This was reported in BPO 32117 and updated in Python 3.8 to allow the unparenthesized form.
RelaxedDecorator(RelaxedDecoratorError)
Represents the use of a “relaxed” PEP 614 decorator before Python 3.9.
§Examples
Prior to Python 3.9, decorators were defined to be dotted_names, optionally followed by
an argument list. For example:
@buttons.clicked.connect
def foo(): ...
@buttons.clicked.connect(1, 2, 3)
def foo(): ...As pointed out in the PEP, this prevented reasonable extensions like subscripts:
buttons = [QPushButton(f'Button {i}') for i in range(10)]
@buttons[0].clicked.connect
def spam(): ...Python 3.9 removed these restrictions and expanded the decorator grammar to include any assignment expression and include cases like the example above.
PositionalOnlyParameter
Represents the use of a PEP 570 positional-only parameter before Python 3.8.
§Examples
Python 3.8 added the / syntax for marking preceding parameters as positional-only:
def foo(a, b, /, c): ...This means a and b in this case can only be provided by position, not by name. In other
words, this code results in a TypeError at runtime:
>>> def foo(a, b, /, c): ...
...
>>> foo(a=1, b=2, c=3)
Traceback (most recent call last):
File "<python-input-3>", line 1, in <module>
foo(a=1, b=2, c=3)
~~~^^^^^^^^^^^^^^^
TypeError: foo() got some positional-only arguments passed as keyword arguments: 'a, b'TypeParameterList
Represents the use of a type parameter list before Python 3.12.
§Examples
Before Python 3.12, generic parameters had to be declared separately using a class like
typing.TypeVar, which could then be used in a function or class definition:
from typing import Generic, TypeVar
T = TypeVar("T")
def f(t: T): ...
class C(Generic[T]): ...PEP 695, included in Python 3.12, introduced the new type parameter syntax, which allows these to be written more compactly and without a separate type variable:
def f[T](t: T): ...
class C[T]: ...TypeAliasStatement
TypeParamDefault
Pep701FString(FStringKind)
Represents the use of a PEP 701 f-string before Python 3.12.
§Examples
As described in the PEP, each of these cases were invalid before Python 3.12:
# nested quotes
f'Magic wand: { bag['wand'] }'
# escape characters
f"{'\n'.join(a)}"
# comments
f'''A complex trick: {
bag['bag'] # recursive bags!
}'''
# arbitrary nesting
f"{f"{f"{f"{f"{f"{1+1}"}"}"}"}"}"These restrictions were lifted in Python 3.12, meaning that all of these examples are now valid.
ParenthesizedContextManager
Represents the use of a parenthesized with item before Python 3.9.
§Examples
As described in BPO 12782, with uses like this were not allowed on Python 3.8:
with (open("a_really_long_foo") as foo,
open("a_really_long_bar") as bar):
passbecause parentheses were not allowed within the with statement itself (see this comment
in particular). However, parenthesized expressions were still allowed, including the cases
below, so the issue can be pretty subtle and relates specifically to parenthesized items
with as bindings.
with (foo, bar): ... # okay
with (
open('foo.txt')) as foo: ... # also okay
with (
foo,
bar,
baz,
): ... # also okay, just a tuple
with (
foo,
bar,
baz,
) as tup: ... # also okay, binding the tupleThis restriction was lifted in 3.9 but formally included in the release notes for 3.10.
StarExpressionInIndex
Represents the use of a PEP 646 star expression in an index.
§Examples
Before Python 3.11, star expressions were not allowed in index/subscript operations (within
square brackets). This restriction was lifted in PEP 646 to allow for star-unpacking of
typing.TypeVarTuples, also added in Python 3.11. As such, this is the primary motivating
example from the PEP:
from typing import TypeVar, TypeVarTuple
DType = TypeVar('DType')
Shape = TypeVarTuple('Shape')
class Array(Generic[DType, *Shape]): ...But it applies to simple indexing as well:
vector[*x]
array[a, *b]StarAnnotation
Represents the use of a PEP 646 star annotations in a function definition.
§Examples
Before Python 3.11, star annotations were not allowed in function definitions. This
restriction was lifted in PEP 646 to allow type annotations for typing.TypeVarTuple,
also added in Python 3.11:
from typing import TypeVarTuple
Ts = TypeVarTuple('Ts')
def foo(*args: *Ts): ...Unlike UnsupportedSyntaxErrorKind::StarExpressionInIndex, this does not include any
other annotation positions:
x: *Ts # Syntax error
def foo(x: *Ts): ... # Syntax errorUnparenthesizedUnpackInFor
Represents the use of tuple unpacking in a for statement iterator clause before Python
3.9.
§Examples
Like UnsupportedSyntaxErrorKind::StarTuple in return and yield statements, prior to
Python 3.9, tuple unpacking in the iterator clause of a for statement required
parentheses:
# valid on Python 3.8 and earlier
for i in (*a, *b): ...Omitting the parentheses was invalid:
for i in *a, *b: ... # SyntaxErrorThis was changed as part of the PEG parser rewrite included in Python 3.9 but not documented directly until the Python 3.11 release.
UnparenthesizedExceptionTypes
Represents the use of multiple exception names in an except clause without an as binding, before Python 3.14.
§Examples
Before Python 3.14, catching multiple exceptions required parentheses like so:
try:
...
except (ExceptionA, ExceptionB, ExceptionC):
...Starting with Python 3.14, thanks to PEP 758, it was permitted to omit the parentheses:
try:
...
except ExceptionA, ExceptionB, ExceptionC:
...However, parentheses are still required in the presence of an as:
try:
...
except (ExceptionA, ExceptionB, ExceptionC) as e:
...TemplateStrings
Represents the use of a template string (t-string) literal prior to the implementation of PEP 750 in Python 3.14.
Trait Implementations§
Source§impl Clone for UnsupportedSyntaxErrorKind
impl Clone for UnsupportedSyntaxErrorKind
Source§fn clone(&self) -> UnsupportedSyntaxErrorKind
fn clone(&self) -> UnsupportedSyntaxErrorKind
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for UnsupportedSyntaxErrorKind
impl Debug for UnsupportedSyntaxErrorKind
Source§impl GetSize for UnsupportedSyntaxErrorKind
impl GetSize for UnsupportedSyntaxErrorKind
Source§fn get_heap_size(&self) -> usize
fn get_heap_size(&self) -> usize
Source§fn get_heap_size_with_tracker<TRACKER: GetSizeTracker>(
&self,
tracker: TRACKER,
) -> (usize, TRACKER)
fn get_heap_size_with_tracker<TRACKER: GetSizeTracker>( &self, tracker: TRACKER, ) -> (usize, TRACKER)
tracker. Read moreSource§fn get_stack_size() -> usize
fn get_stack_size() -> usize
Source§fn get_size_with_tracker<T>(&self, tracker: T) -> (usize, T)where
T: GetSizeTracker,
fn get_size_with_tracker<T>(&self, tracker: T) -> (usize, T)where
T: GetSizeTracker,
tracker. Read moreSource§impl Hash for UnsupportedSyntaxErrorKind
impl Hash for UnsupportedSyntaxErrorKind
impl Copy for UnsupportedSyntaxErrorKind
impl Eq for UnsupportedSyntaxErrorKind
impl StructuralPartialEq for UnsupportedSyntaxErrorKind
Auto Trait Implementations§
impl Freeze for UnsupportedSyntaxErrorKind
impl RefUnwindSafe for UnsupportedSyntaxErrorKind
impl Send for UnsupportedSyntaxErrorKind
impl Sync for UnsupportedSyntaxErrorKind
impl Unpin for UnsupportedSyntaxErrorKind
impl UnsafeUnpin for UnsupportedSyntaxErrorKind
impl UnwindSafe for UnsupportedSyntaxErrorKind
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more