Warning
Most of the documentation was written prior to version 0.5 and needs to be updated. This work has now started for version 0.7 and we aim to have it completed before version 0.8 is available.
Friendly SyntaxError tracebacks - in English¶
Friendly aims to provide friendlier feedback when an exception is raised than what is done by Python. This file contains only examples of SyntaxError and its sub-classes. Some tests may appear to be repetitive to a human reader but they are may be included to ensure more complete test coverage.
Note
The content of this page is generated by running
trb_syntax_english.py located in the tests/
directory.
This needs to be done explicitly, independently of updating the
documentation using Sphinx.
On Windows, if Sphinx is installed on your computer, it is suggested
instead to run make_trb.bat in the root directory as it will create
similar files for all languages and update the documentation.
Friendly-traceback version: 0.7.53 Python version: 3.11.0
(1) Using ‘and’ in import statement¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\and_in_import_statement.py", line 1
from math import sin and cos
^^^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\and_in_import_statement.py'
at the location indicated.
1| from math import sin and cos
^^^
The Python keyword `and` can only be used for boolean expressions.
Perhaps you meant to write
`from math import sin , cos`
(2) Using ‘and’ after comma in import statement¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\and_in_import_statement_2.py", line 1
from math import sin, tan, and cos
^^^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\and_in_import_statement_2.py'
at the location indicated.
1| from math import sin, tan, and cos
^^^
The Python keyword `and` can only be used for boolean expressions.
Perhaps you meant to write
`from math import sin, tan, cos`
(3) Annotated name cannot be global¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\annotated_name_global.py", line 4
var:int = 1
^^^^^^^^^^^
SyntaxError: annotated name 'var' can't be global
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\annotated_name_global.py'
at the location indicated.
4| var:int = 1
^^^
The object named `var` is defined with type annotation
as a local variable. It cannot be declared to be a global variable.
(4) Incorrect use of ‘from module import … as …¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\as_instead_of_comma_in_import.py", line 2
from math import (sin, cos) as funcs
^^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\as_instead_of_comma_in_import.py'
at the location indicated.
2| from math import (sin, cos) as funcs
^^
I am guessing that you are trying to import at least one object
from module `math` and rename it using the Python keyword `as`;
this keyword can only be used to rename one object at a time
using a well defined syntax.
I suggest that you split up any such import statement with each object
renamed on a separate line as follows:
from math import object_1 as name_1
from math import object_2 as name_2 # if needed
(5) Assign instead of equal (or walrus).¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_instead_of_equal.py", line 1
a = (b = 2) # issue #65
^^^^^
SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?
Perhaps you needed `==` or `:=` instead of `=`.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_instead_of_equal.py'
at the location indicated.
1| a = (b = 2) # issue #65
^^^^^
You used an assignment operator `=`; perhaps you meant to use
an equality operator, `==`, or the walrus operator `:=`.
(6) Name assigned prior to global declaration¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_name_before_global_1.py", line 7
global aa, bb, cc, dd
^^^^^^^^^^^^^^^^^^^^^
SyntaxError: name 'cc' is assigned to before global declaration
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_name_before_global_1.py'
at the location indicated.
7| global aa, bb, cc, dd
^^^^^^ ^^
You assigned a value to the variable `cc`
before declaring it as a global variable.
(7) Name used prior to global declaration¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_name_before_global_2.py", line 7
global var
^^^^^^^^^^
SyntaxError: name 'var' is used prior to global declaration
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_name_before_global_2.py'
at the location indicated.
7| global var
^^^^^^ ^^^
You used the variable `var`
before declaring it as a global variable.
(8) Name used prior to nonlocal declaration¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_name_before_nonlocal_1.py", line 11
nonlocal pp, qq
^^^^^^^^^^^^^^^
SyntaxError: name 'qq' is used prior to nonlocal declaration
Did you forget to write `nonlocal` first?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_name_before_nonlocal_1.py'
at the location indicated.
11| nonlocal pp, qq
^^^^^^^^ ^^
You used the variable `qq`
before declaring it as a nonlocal variable.
(9) Name assigned prior to nonlocal declaration¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_name_before_nonlocal_2.py", line 9
nonlocal s
^^^^^^^^^^
SyntaxError: name 's' is assigned to before nonlocal declaration
Did you forget to add `nonlocal`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_name_before_nonlocal_2.py'
at the location indicated.
9| nonlocal s
^^^^^^^^ ^
You assigned a value to the variable `s`
before declaring it as a nonlocal variable.
(10) Assign to conditional expression¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_to_conditional.py", line 3
a if 1 else b = 1
^^^^^^^^^^^^^
SyntaxError: cannot assign to conditional expression
You can only assign objects to identifiers (variable names).
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_to_conditional.py'
at the location indicated.
3| a if 1 else b = 1
^^^^^^^^^^^^^
On the left-hand side of an equal sign, you have a
conditional expression instead of the name of a variable.
a if 1 else b = ...
^^^^^^^^^^^^^
You can only assign objects to identifiers (variable names).
(11) Assignment to keyword (__debug__)¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_to_debug.py", line 4
__debug__ = 1
^^^^^^^^^
SyntaxError: cannot assign to __debug__
You cannot assign a value to `__debug__`.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_to_debug.py'
at the location indicated.
4| __debug__ = 1
^^^^^^^^^
`__debug__` is a constant in Python; you cannot assign it a different value.
(12) Assignment to keyword (__debug__)¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_to_debug2.py", line 4
a.__debug__ = 1
^^^^^^^^^^^
SyntaxError: cannot assign to __debug__
You cannot assign a value to `__debug__`.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_to_debug2.py'
at the location indicated.
4| a.__debug__ = 1
^^^^^^^^^
`__debug__` is a constant in Python; you cannot assign it a different value.
(13) Assignment to Ellipsis symbol¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_to_ellipsis.py", line 4
... = 1
^^^
SyntaxError: cannot assign to ellipsis here. Maybe you meant '==' instead of '='?
You cannot assign a value to the ellipsis symbol [`...`].
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_to_ellipsis.py'
at the location indicated.
4| ... = 1
^^^
The ellipsis symbol `...` is a constant in Python;you cannot assign it a different value.
(14) Cannot assign to f-string¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_to_f_string.py", line 6
f'{x}' = 42
^^^^^^
SyntaxError: cannot assign to f-string expression here. Maybe you meant '==' instead of '='?
You can only assign objects to identifiers (variable names).
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_to_f_string.py'
at the location indicated.
6| f'{x}' = 42
^^^^^^
You wrote an expression that has the f-string `f'{x}'`
on the left-hand side of the equal sign.
An f-string should only appear on the right-hand side of an equal sign.
You can only assign objects to identifiers (variable names).
(15) Cannot assign to function call: single = sign¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_to_function_call_1.py", line 6
len('a') = 3
^^^^^^^^
SyntaxError: cannot assign to function call here. Maybe you meant '==' instead of '='?
You can only assign objects to identifiers (variable names).
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_to_function_call_1.py'
at the location indicated.
6| len('a') = 3
^^^^^^^^
You wrote the expression
len('a') = ...
^^^^^^^^
where `len('a')`, on the left-hand side of the equal sign, either is
or includes a function call and is not simply the name of a variable.
You can only assign objects to identifiers (variable names).
(16) Cannot assign to function call: two = signs¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_to_function_call_2.py", line 6
func(a, b=3) = 4
^^^^^^^^^^^^
SyntaxError: cannot assign to function call here. Maybe you meant '==' instead of '='?
You can only assign objects to identifiers (variable names).
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_to_function_call_2.py'
at the location indicated.
6| func(a, b=3) = 4
^^^^^^^^^^^^
You wrote the expression
func(a, b=3) = ...
^^^^^^^^^^^^
where `func(a, b=3)`, on the left-hand side of the equal sign, either is
or includes a function call and is not simply the name of a variable.
You can only assign objects to identifiers (variable names).
(17) Cannot assign to function call: continues on second line¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_to_function_call_3.py", line 6
a = f(1, 2, # this is a comment
^^^^^^^^^^^^^^^^^^^^^^^^^^^^-->
SyntaxError: cannot assign to function call
You can only assign objects to identifiers (variable names).
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_to_function_call_3.py'
at the location indicated.
-->6| a = f(1, 2, # this is a comment
^^^^^^^-->
7| 3, 4) = 5
You wrote the expression
f(1, 2,...) = ...
^^^^^^^-->
where `f(1, 2,...)`, on the left-hand side of the equal sign, either is
or includes a function call and is not simply the name of a variable.
You can only assign objects to identifiers (variable names).
(18) Assign to generator expression¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_to_generator.py", line 3
(x for x in x) = 1
^^^^^^^^^^^^^^
SyntaxError: cannot assign to generator expression
You can only assign objects to identifiers (variable names).
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_to_generator.py'
at the location indicated.
3| (x for x in x) = 1
^^^^^^^^^^^^^^
On the left-hand side of an equal sign, you have a
generator expression instead of the name of a variable.
You can only assign objects to identifiers (variable names).
(19) Cannot assign to literal - 4¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_to_literal_dict.py", line 7
{1 : 2, 2 : 4} = 5
^^^^^^^^^^^^^^
SyntaxError: cannot assign to dict literal here. Maybe you meant '==' instead of '='?
You can only assign objects to identifiers (variable names).
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_to_literal_dict.py'
at the location indicated.
7| {1 : 2, 2 : 4} = 5
^^^^^^^^^^^^^^
You wrote an expression like
{1 : 2, 2 : 4} = 5
where `{1 : 2, 2 : 4}`, on the left-hand side of the equal sign,
is or includes an actual object of type `dict`
and is not simply the name of a variable.
You can only assign objects to identifiers (variable names).
(20) Cannot assign to literal int¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_to_literal_int.py", line 3
1 = a
^
SyntaxError: cannot assign to literal here. Maybe you meant '==' instead of '='?
Perhaps you meant to write `a = 1`
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_to_literal_int.py'
at the location indicated.
3| 1 = a
^
You wrote an expression like
1 = a
where `1`, on the left-hand side of the equal sign,
is or includes an actual object of type `int`
and is not simply the name of a variable.
Perhaps you meant to write:
a = 1
(21) Cannot assign to literal int - 2¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_to_literal_int_2.py", line 3
1 = 2
^
SyntaxError: cannot assign to literal here. Maybe you meant '==' instead of '='?
You can only assign objects to identifiers (variable names).
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_to_literal_int_2.py'
at the location indicated.
3| 1 = 2
^
You wrote an expression like
1 = 2
where `1`, on the left-hand side of the equal sign,
is or includes an actual object of type `int`
and is not simply the name of a variable.
You can only assign objects to identifiers (variable names).
(22) Cannot assign to literal - 5¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_to_literal_int_3.py", line 4
1 = a = b
^
SyntaxError: cannot assign to literal
You can only assign objects to identifiers (variable names).
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_to_literal_int_3.py'
at the location indicated.
4| 1 = a = b
^
You wrote an expression like
1 = variable_name
where `1`, on the left-hand side of the equal sign,
is or includes an actual object of type `int`
and is not simply the name of a variable.
You can only assign objects to identifiers (variable names).
(23) Cannot assign to literal - 3¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_to_literal_set.py", line 7
{1, 2, 3} = 4
^^^^^^^^^
SyntaxError: cannot assign to set display here. Maybe you meant '==' instead of '='?
You can only assign objects to identifiers (variable names).
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_to_literal_set.py'
at the location indicated.
7| {1, 2, 3} = 4
^^^^^^^^^
You wrote an expression like
{1, 2, 3} = 4
where `{1, 2, 3}`, on the left-hand side of the equal sign,
is or includes an actual object of type `set`
and is not simply the name of a variable.
You can only assign objects to identifiers (variable names).
(24) Assign to keyword def¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_to_keyword_def.py", line 3
def = 2
^
SyntaxError: invalid syntax
Python keywords cannot be used as identifiers (variable names).
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_to_keyword_def.py'
at the location indicated.
3| def = 2
^^^
You were trying to assign a value to the Python keyword `def`.
This is not allowed.
(25) Assign to keyword else¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_to_keyword_else.py", line 3
else = 1
^^^^
SyntaxError: invalid syntax
Python keywords cannot be used as identifiers (variable names).
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_to_keyword_else.py'
at the location indicated.
3| else = 1
^^^^
You were trying to assign a value to the Python keyword `else`.
This is not allowed.
(26) Assignment to keyword (None)¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_to_keyword_none.py", line 4
None = 1
^^^^
SyntaxError: cannot assign to None
You cannot assign a value to `None`.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_to_keyword_none.py'
at the location indicated.
4| None = 1
^^^^
`None` is a constant in Python; you cannot assign it a different value.
(27) Assign to math operation¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_to_operation.py", line 4
a + 1 = 2
^^^^^
SyntaxError: cannot assign to expression here. Maybe you meant '==' instead of '='?
Perhaps you needed `==` instead of `=`.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_to_operation.py'
at the location indicated.
4| a + 1 = 2
^^^^^
You wrote an expression that includes some mathematical operations
on the left-hand side of the equal sign which should be
only used to assign a value to a variable.
(28) Assign to yield expression¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assign_to_yield_expression.py", line 1
(yield i) = 3
^^^^^^^
SyntaxError: cannot assign to yield expression here. Maybe you meant '==' instead of '='?
You can only assign objects to identifiers (variable names).
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assign_to_yield_expression.py'
at the location indicated.
1| (yield i) = 3
^^^^^
You wrote an expression that includes the `yield` keyword
on the left-hand side of the equal sign.
You cannot assign a value to such an expression.
Note that, like the keyword `return`,
`yield` can only be used inside a function.
(29) Augmented assignment inside comprehension¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assignment_expression_cannot_rebind.py", line 1
a = [(i := 1) for i in [1]]
^
SyntaxError: assignment expression cannot rebind comprehension iteration variable 'i'
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assignment_expression_cannot_rebind.py'
at the location indicated.
1| a = [(i := 1) for i in [1]]
^
You are using the augmented assignment operator `:=` inside
a comprehension to assign a value to the iteration variable `i`.
This variable is meant to be used only inside the comprehension.
The augmented assignment operator is normally used to assign a value
to a variable so that the variable can be reused later.
This is not possible for variable `i`.
(30) Augmented assignment inside comprehension - inner loop¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\assignment_expression_cannot_rebind_2.py", line 1
[i for i in range(5) if (j := 0) for k[j + 1] in range(5)]
^
SyntaxError: comprehension inner loop cannot rebind assignment expression target 'j'
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\assignment_expression_cannot_rebind_2.py'
at the location indicated.
1| [i for i in range(5) if (j := 0) for k[j + 1] in range(5)]
^
You are using the augmented assignment operator `:=` inside
a comprehension to assign a value to the iteration variable `j`.
This variable is meant to be used only inside the comprehension.
The augmented assignment operator is normally used to assign a value
to a variable so that the variable can be reused later.
This is not possible for variable `j`.
(31) def: missing parentheses¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\async_def_missing_parens.py", line 1
async def name:
^
SyntaxError: expected '('
Did you forget parentheses?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\async_def_missing_parens.py'
at the location indicated.
1| async def name:
^
Perhaps you forgot to include parentheses.
You might have meant to write
async def name():
(32) Augmented assignment to literal¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\augmented_assignment_to_literal.py", line 1
if "word" := True:
^^^^^^
SyntaxError: cannot use assignment expressions with literal
You can only assign objects to identifiers (variable names).
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\augmented_assignment_to_literal.py'
at the location indicated.
1| if "word" := True:
^^^^^^
You cannot use the augmented assignment operator `:=`,
sometimes called the walrus operator, with literals like `"word"`.
You can only assign objects to identifiers (variable names).
(33) Walrus/Named assignment depending on Python version¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\augmented_assigment_with_true.py", line 4
(True := 1)
^^^^
SyntaxError: cannot use assignment expressions with True
You cannot assign a value to `True`.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\augmented_assigment_with_true.py'
at the location indicated.
4| (True := 1)
^^^^
`True` is a constant in Python; you cannot assign it a different value.
(34) Backslash instead of slash¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\backslash_instead_of_slash.py", line 1
a = 3 \ 4.0
^
SyntaxError: unexpected character after line continuation character
Did you mean to divide by 4.0?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\backslash_instead_of_slash.py'
at the location indicated.
1| a = 3 \ 4.0
^^^
You are using the continuation character `\` outside of a string,
and it is followed by some other character(s).
I am guessing that you wanted to divide by the number 4.0
and wrote \ instead of /.
(35) Brackets instead of parentheses¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\bracket_instead_of_paren.py", line 1
print(sum[i for i in [1, 2, 3] if i%2==0])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
Did you forget something between `sum` and `[`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\bracket_instead_of_paren.py'
at the location indicated.
1| print(sum[i for i in [1, 2, 3] if i%2==0])
^^^^
Python indicates that the error is caused by `[` written immediately after `sum`.
It is possible that you forgot a comma between items in a tuple,
or between function arguments,
at the position indicated by ^.
Perhaps you meant to insert an operator like `+, -, *`
between `sum` and `[`.
The following lines of code would not cause any `SyntaxError`:
print(sum, [i for i in [1, 2, 3] if i%2==0])
print(sum + [i for i in [1, 2, 3] if i%2==0])
print(sum - [i for i in [1, 2, 3] if i%2==0])
print(sum * [i for i in [1, 2, 3] if i%2==0])
Note: these are just some of the possible choices and that
some of them might raise other types of exceptions.
There is an additional possibility.
You used square brackets, `[...]` instead of parentheses.
Write the following instead:
print(sum(i for i in [1, 2, 3] if i%2==0))
(36) break outside loop¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\break_outside_loop.py", line 4
break
^^^^^
SyntaxError: 'break' outside loop
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\break_outside_loop.py'
at the location indicated.
4| break
^^^^^
The Python keyword `break` can only be used inside a `for` loop or inside a `while` loop.
(37) Cannot assign to attribute here.¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\cannot_assign_to_attribute_here.py", line 1
if x.a = 1:
^^^
SyntaxError: cannot assign to attribute here. Maybe you meant '==' instead of '='?
Perhaps you needed `==` instead of `=`.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\cannot_assign_to_attribute_here.py'
at the location indicated.
1| if x.a = 1:
^^^
You likely used an assignment operator `=` instead of an equality operator `==`.
The following statement would not contain a syntax error:
if x.a == 1:
(38) Cannot guess the cause¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\cannot_guess_the_cause.py", line 1
SyntaxErrors can be annoying!
^^^
SyntaxError: invalid syntax
Friendly-traceback does not know the cause of this error.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\cannot_guess_the_cause.py'
at the location indicated.
1| SyntaxErrors can be annoying!
^^^
Currently, I cannot guess the likely cause of this error.
Try to examine closely the line indicated as well as the line
immediately above to see if you can identify some misspelled
word, or missing symbols, like (, ), [, ], :, etc.
Unless your code uses type annotations, which are beyond our scope,
if you think that this is something which should be handled
by friendly, please report this case to
https://github.com/friendly-traceback/friendly-traceback/issues
(39) Cannot use star operator¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\cannot_use_star.py", line 3
*a
^^
SyntaxError: can't use starred expression here
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\cannot_use_star.py'
at the location indicated.
3| *a
^^
The star operator `*` is interpreted to mean that
iterable unpacking is to be used to assign a name
to each item of an iterable, which does not make sense here.
(40) Cannot use double star operator¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\cannot_use_double_star.py", line 4
(**k)
^^
SyntaxError: f-string: cannot use double starred expression here
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\cannot_use_double_star.py'
at the location indicated.
4| print(f"{**k}")
^
The double star operator `**` is likely interpreted to mean that
dict unpacking is to be used which is not allowed or does not make sense here.
(41) Missing class name¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\class_missing_name.py", line 1
class:
^
SyntaxError: invalid syntax
A class needs a name.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\class_missing_name.py'
at the location indicated.
1| class:
^
A `class` statement requires a name:
class SomeName:
...
(42) Missing () for tuples in comprehension¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\comprehension_missing_tuple_paren.py", line 1
x = [i, i**2 for i in range(10)]
^^^^^^^
SyntaxError: did you forget parentheses around the comprehension target?
Did you forget parentheses?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\comprehension_missing_tuple_paren.py'
at the location indicated.
1| x = [i, i**2 for i in range(10)]
^^^^^^^
I am guessing that you were writing a comprehension or a generator expression
and forgot to include parentheses around tuples.
As an example, instead of writing
[i, i**2 for i in range(10)]
you would need to write
[(i, i**2) for i in range(10)]
(43) Comprehension with condition (no else)¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\comprehension_with_condition_no_else.py", line 1
a = [f(x) if condition for x in sequence]
^^^^^^^^^^^^^^^^^
SyntaxError: expected 'else' after 'if' expression
Did you forget to add `else`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\comprehension_with_condition_no_else.py'
at the location indicated.
1| a = [f(x) if condition for x in sequence]
^^^^^^^^^^^^^^^^^
An `else some_value` clause was expected after the `if` expression.
(44) Comprehension with condition (with else)¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\comprehension_with_condition_with_else.py", line 1
a = [f(x) for x in sequence if condition else other]
^^^^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\comprehension_with_condition_with_else.py'
at the location indicated.
1| a = [f(x) for x in sequence if condition else other]
^^^^
I am guessing that you were writing a comprehension or a generator expression
and use the wrong order for a condition.
The correct order depends if there is an `else` clause or not.
For example, the correct order for a list comprehensions with
condition can be either
[f(x) if condition else other for x in sequence] # 'if' before 'for'
or, if there is no `else`
[f(x) for x in sequence if condition] # 'if' after 'for'
(45) continue outside loop¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\continue_outside_loop.py", line 4
continue
^^^^^^^^
SyntaxError: 'continue' not properly in loop
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\continue_outside_loop.py'
at the location indicated.
4| continue
^^^^^^^^
The Python keyword `continue` can only be used inside a `for` loop or inside a `while` loop.
(46) Copy/paste from interpreter¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\copy_pasted_code.py", line 2
>>> print("Hello World!")
^^
SyntaxError: invalid syntax
Did you use copy-paste?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\copy_pasted_code.py'
at the location indicated.
2| >>> print("Hello World!")
^^^
It looks like you copy-pasted code from an interactive interpreter.
The Python prompt, `>>>`, should not be included in your code.
(47) Copy/paste from interpreter - 2¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\copy_pasted_code_2.py", line 2
... print("Hello World!")
^^^^^
SyntaxError: invalid syntax
Did you use copy-paste?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\copy_pasted_code_2.py'
at the location indicated.
2| ... print("Hello World!")
^^^
It looks like you copy-pasted code from an interactive interpreter.
The Python prompt, `...`, should not be included in your code.
(48) def: positional arg after kwargs¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_arg_after_kwarg.py", line 1
def test(a, **kwargs, b):
^
SyntaxError: arguments cannot follow var-keyword argument
Positional arguments must come before keyword arguments.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_arg_after_kwarg.py'
at the location indicated.
1| def test(a, **kwargs, b):
^
Positional arguments must come before keyword arguments.
`b` is a positional argument that appears after one or more
keyword arguments in your function definition.
(49) def: named arguments must follow bare *¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_bare_star_arg.py", line 4
def f(*):
^
SyntaxError: named arguments must follow bare *
Did you forget something after `*`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_bare_star_arg.py'
at the location indicated.
4| def f(*):
^
Assuming you were defining a function, you need
to replace `*` by either `*arguments` or
by `*, named_argument=value`.
(50) def: misused as code block¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_code_block.py", line 3
def :
^
SyntaxError: invalid syntax
A function needs a name.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_code_block.py'
at the location indicated.
3| def :
^
You tried to define a function and did not use the correct syntax.
The correct syntax is:
def name ( ... ):
(51) def: misused as code block - 2¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_code_block_2.py", line 2
def :
^
SyntaxError: invalid syntax
Functions and methods need a name.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_code_block_2.py'
at the location indicated.
2| def :
^
You tried to define a function or method and did not use the correct syntax.
The correct syntax is:
def name ( ... ):
(52) Dotted name as function argument¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_dotted_argument.py", line 3
def test(x.y):
^
SyntaxError: invalid syntax
Did you mean to write a comma?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_dotted_argument.py'
at the location indicated.
3| def test(x.y):
^
You cannot use dotted names as function arguments.
Perhaps you meant to write a comma.
(53) Dotted name as function argument¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_dotted_argument_2.py", line 2
def test(x., y):
^
SyntaxError: invalid syntax
You cannot use dotted names as function arguments.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_dotted_argument_2.py'
at the location indicated.
2| def test(x., y):
^
You cannot use dotted names as function arguments.
(54) Dotted function name¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_dotted_function_name.py", line 3
def test.x():
^
SyntaxError: expected '('
You cannot use dots in function names.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_dotted_function_name.py'
at the location indicated.
3| def test.x():
^
You cannot use dots in function names.
(55) def: dict as argument¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_dict_as_arg.py", line 1
def test({'a': 1}, y): # dict as first argument
^
SyntaxError: invalid syntax
You cannot have any explicit dict or set as function arguments.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_dict_as_arg.py'
at the location indicated.
1| def test({'a': 1}, y): # dict as first argument
^
You cannot have any explicit dict or set as function arguments.
You can only use identifiers (variable names) as function arguments.
(56) def: arguments must be unique in function definition¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_duplicate_arg.py", line 4
def f(aa=1, aa=2):
^^
SyntaxError: duplicate argument 'aa' in function definition
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_duplicate_arg.py'
at the location indicated.
4| def f(aa=1, aa=2):
^^ ^^
You have defined a function repeating the argument
aa
Each argument should appear only once in a function definition.
(57) def: semicolon after colon¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_extra_semi_colon.py", line 1
def test():;
^
SyntaxError: invalid syntax
Did you write something by mistake after the colon?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_extra_semi_colon.py'
at the location indicated.
1| def test():;
^
A function definition statement must end with a colon.
A block of code must come after the colon.
Removing `;`, might fix the problem.
(58) def: extra comma¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_extra_comma.py", line 1
def test(a,,b):
^
SyntaxError: invalid syntax
Did you mean to write `,`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_extra_comma.py'
at the location indicated.
1| def test(a,,b):
^
I suspect you made a typo and added `,` by mistake.
The following statement contains no syntax error:
def test(a,b):
(59) def: unspecified keywords before /¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_forward_slash_1.py", line 1
def test(a, **kwargs, /):
^
SyntaxError: arguments cannot follow var-keyword argument
Keyword arguments must appear after the `/` symbol.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_forward_slash_1.py'
at the location indicated.
1| def test(a, **kwargs, /):
^
`/` indicates that the previous arguments in a function definition
are positional arguments.
You have unspecified keyword arguments that appear before
the symbol `/`.
(60) def: / before star¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_forward_slash_2.py", line 1
def test(a, *, b, /):
^
SyntaxError: / must be ahead of *
`*` must appear after `/` in a function definition.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_forward_slash_2.py'
at the location indicated.
1| def test(a, *, b, /):
^
`/` indicates that the previous arguments in a function definition
are positional arguments.
However, `*` indicates that the arguments
that follow must be keyword arguments.
When they are used together, `/` must appear before `*`.
(61) def: / before star arg¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_forward_slash_3.py", line 1
def test(a, *arg, /):
^
SyntaxError: / must be ahead of *
`*arg` must appear after `/` in a function definition.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_forward_slash_3.py'
at the location indicated.
1| def test(a, *arg, /):
^
`/` indicates that the previous arguments in a function definition
are positional arguments.
`*arg` must appear after `/` in a function definition.
(62) def: / used twice¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_forward_slash_4.py", line 1
def test(a, /, b, /):
^
SyntaxError: / may appear only once
You can only use `/` once in a function definition.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_forward_slash_4.py'
at the location indicated.
1| def test(a, /, b, /):
^
You can only use `/` once in a function definition.
(63) def: non-identifier as a function name¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_function_name_invalid.py", line 3
def 2be():
^
SyntaxError: invalid decimal literal
You wrote an invalid function name.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_function_name_invalid.py'
at the location indicated.
3| def 2be():
^^
Python tells us that you have written an invalid number.
However, I think that the problem might be the following.
The name of a function must be a valid Python identifier,
that is a name that begins with a letter or an underscore character, `_`,
and which contains only letters, digits or the underscore character.
(64) def: using a string as a function name¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_function_name_string.py", line 3
def "function"():
^^^^^^^^^^
SyntaxError: invalid syntax
The name of a function must be a valid Python identifier,
that is a name that begins with a letter or an underscore character, `_`,
and which contains only letters, digits or the underscore character.
You attempted to use a string as a function name.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_function_name_string.py'
at the location indicated.
3| def "function"():
^^^^^^^^^^
The name of a function must be a valid Python identifier,
that is a name that begins with a letter or an underscore character, `_`,
and which contains only letters, digits or the underscore character.
You attempted to use a string as a function name.
(65) def: keyword cannot be argument in def - 1¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_keyword_as_arg_1.py", line 5
def f(None=1):
^^^^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_keyword_as_arg_1.py'
at the location indicated.
5| def f(None=1):
^^^^
I am guessing that you tried to use the Python keyword
`None` as an argument in the definition of a function
where an identifier (variable name) was expected.
(66) def: keyword cannot be argument in def - 2¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_keyword_as_arg_2.py", line 5
def f(x, True):
^^^^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_keyword_as_arg_2.py'
at the location indicated.
5| def f(x, True):
^^^^
I am guessing that you tried to use the Python keyword
`True` as an argument in the definition of a function
where an identifier (variable name) was expected.
(67) def: keyword cannot be argument in def - 3¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_keyword_as_arg_3.py", line 5
def f(*None):
^^^^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_keyword_as_arg_3.py'
at the location indicated.
5| def f(*None):
^^^^
I am guessing that you tried to use the Python keyword
`None` as an argument in the definition of a function
where an identifier (variable name) was expected.
(68) def: keyword cannot be argument in def - 4¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_keyword_as_arg_4.py", line 5
def f(**None):
^^^^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_keyword_as_arg_4.py'
at the location indicated.
5| def f(**None):
^^^^
I am guessing that you tried to use the Python keyword
`None` as an argument in the definition of a function
where an identifier (variable name) was expected.
(69) def: Python keyword as function name¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_keyword_as_name.py", line 3
def pass():
^^^^
SyntaxError: invalid syntax
You cannot use a Python keyword as a function name.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_keyword_as_name.py'
at the location indicated.
3| def pass():
^^^^
You tried to use the Python keyword `pass` as a function name.
There are more syntax errors later in your code.
(70) def: list as argument - 1¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_list_as_arg_1.py", line 1
def test([x], y): # list as first argument
^
SyntaxError: invalid syntax
You cannot have explicit lists as function arguments.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_list_as_arg_1.py'
at the location indicated.
1| def test([x], y): # list as first argument
^
You cannot have explicit lists as function arguments.
You can only use identifiers (variable names) as function arguments.
(71) def: list as argument - 2¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_list_as_arg_2.py", line 1
def test(x, [y]): # list as second argument, after comma
^
SyntaxError: invalid syntax
You cannot have explicit lists as function arguments.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_list_as_arg_2.py'
at the location indicated.
1| def test(x, [y]): # list as second argument, after comma
^
You cannot have explicit lists as function arguments.
You can only use identifiers (variable names) as function arguments.
(72) def: missing colon¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_missing_colon.py", line 1
def test()
^
SyntaxError: expected ':'
Did you forget a colon `:`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_missing_colon.py'
at the location indicated.
1| def test()
^
You wrote a statement beginning with
`def` but forgot to add a colon `:` at the end.
(73) def: missing comma between function args¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_missing_comma.py", line 4
def a(b, c d):
^
SyntaxError: invalid syntax
Did you forget a comma?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_missing_comma.py'
at the location indicated.
4| def a(b, c d):
^^^
Python indicates that the error is caused by `d` written immediately after `c`.
It is possible that you forgot a comma between items in a tuple,
or between function arguments,
at the position indicated by ^.
Perhaps you meant
def a(b, c, d):
^
(74) def: missing parentheses¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_missing_parens.py", line 3
def name:
^
SyntaxError: expected '('
Did you forget parentheses?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_missing_parens.py'
at the location indicated.
3| def name:
^
Perhaps you forgot to include parentheses.
You might have meant to write
def name():
(75) def: missing parentheses around arguments¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_missing_parens_2.py", line 2
def name a, b:
^
SyntaxError: expected '('
Did you forget parentheses?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_missing_parens_2.py'
at the location indicated.
2| def name a, b:
^
Perhaps you forgot to include parentheses.
You might have meant to write
def name (a, b):
(76) def: missing function name¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_missing_name.py", line 3
def ( arg ) :
^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_missing_name.py'
at the location indicated.
3| def ( arg ) :
^
You forgot to name your function.
The correct syntax is:
def name ( ... ):
(77) def: name is parameter and global¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_name_is_parameter_and_global.py", line 6
global x
^^^^^^^^
SyntaxError: name 'x' is parameter and global
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_name_is_parameter_and_global.py'
at the location indicated.
6| global x
^^^^^^^^
You are including the statement
global x
indicating that `x` is a variable defined outside a function.
You are also using the same `x` as an argument for that
function, thus indicating that it should be variable known only
inside that function, which is the contrary of what `global` implied.
(78) def: non-default argument follows default argument¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_non_default_after_default.py", line 5
def test(a=1, b):
^
SyntaxError: non-default argument follows default argument
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_non_default_after_default.py'
at the location indicated.
5| def test(a=1, b):
^
In Python, you can define functions with only positional arguments
def test(a, b, c): ...
or only keyword arguments
def test(a=1, b=2, c=3): ...
or a combination of the two
def test(a, b, c=3): ...
but with the keyword arguments appearing after all the positional ones.
According to Python, you used positional arguments after keyword ones.
(79) Single number used as arg in function def¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_number_as_arg.py", line 1
def f(1):
^
SyntaxError: invalid syntax
You cannot use numbers as function arguments.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_number_as_arg.py'
at the location indicated.
1| def f(1):
^
You used a number as an argument when defining a function.
You can only use identifiers (variable names) as function arguments.
(80) Operator after **
¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_operator_after_2star.py", line 1
def test(**):
^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_operator_after_2star.py'
at the location indicated.
1| def test(**):
^
The `**` operator needs to be followed by an identifier (variable name).
(81) def: operator instead of comma¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_operator_instead_of_comma.py", line 1
def test(a + b):
^
SyntaxError: invalid syntax
Did you mean to write a comma?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_operator_instead_of_comma.py'
at the location indicated.
1| def test(a + b):
^
You cannot have operators as function arguments.
I suspect you made a typo and wrote `+` instead of a comma.
The following statement contains no syntax error:
def test(a , b):
(82) def: operator instead of equal¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_operator_instead_of_equal.py", line 1
def test(a, b=3, c+None):
^
SyntaxError: invalid syntax
Did you mean to write an equal sign?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_operator_instead_of_equal.py'
at the location indicated.
1| def test(a, b=3, c+None):
^
You cannot have operators as function arguments.
I suspect you made a typo and wrote `+` instead of an equal sign.
The following statement contains no syntax error:
def test(a, b=3, c=None):
(83) def: operator instead of name¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_operator_instead_of_name.py", line 1
def test(a, +, b):
^
SyntaxError: invalid syntax
You cannot use `+` as an argument.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_operator_instead_of_name.py'
at the location indicated.
1| def test(a, +, b):
^
I suspect you made a typo and wrote `+` by mistake.
If you replace it by a unique variable name, the result
will contain no syntax error.
(84) def: positional argument follows keyword argument¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_positional_after_keyword_arg.py", line 5
test(a=1, b)
^
SyntaxError: positional argument follows keyword argument
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_positional_after_keyword_arg.py'
at the location indicated.
5| test(a=1, b)
^
In Python, you can call functions with only positional arguments
test(1, 2, 3)
or only keyword arguments
test(a=1, b=2, c=3)
or a combination of the two
test(1, 2, c=3)
but with the keyword arguments appearing after all the positional ones.
According to Python, you used positional arguments after keyword ones.
(85) def: semicolon instead of colon¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_semi_colon_instead_of_colon.py", line 1
def test();
^
SyntaxError: expected ':'
Did you forget a colon?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_semi_colon_instead_of_colon.py'
at the location indicated.
1| def test();
^
Python expected a colon at the position indicated.
You wrote `;` instead of a colon.
(86) def: set as argument¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_set_as_arg.py", line 1
def test(y, {'a', 'b'}): # set as second argument, after comma
^
SyntaxError: invalid syntax
You cannot have any explicit dict or set as function arguments.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_set_as_arg.py'
at the location indicated.
1| def test(y, {'a', 'b'}): # set as second argument, after comma
^
You cannot have any explicit dict or set as function arguments.
You can only use identifiers (variable names) as function arguments.
(87) def: *arg
before /¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_star_arg_before_slash.py", line 1
def test(a, *arg, /):
^
SyntaxError: / must be ahead of *
`*arg` must appear after `/` in a function definition.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_star_arg_before_slash.py'
at the location indicated.
1| def test(a, *arg, /):
^
`/` indicates that the previous arguments in a function definition
are positional arguments.
`*arg` must appear after `/` in a function definition.
(88) def: *
used twice¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_star_used_only_once.py", line 1
def test(a, *arg, *, b=1):
^
SyntaxError: * argument may appear only once
You can only use `*` once in a function definition.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_star_used_only_once.py'
at the location indicated.
1| def test(a, *arg, *, b=1):
^
You can only use `*` once in a function definition.
It must either be used by itself, `*`,
or in the form `*arg`, but not both.
(89) def: *
used twice¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_star_used_only_once_1.py", line 1
def test(a, *, *):
^
SyntaxError: invalid syntax
You can only use `*` once in a function definition.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_star_used_only_once_1.py'
at the location indicated.
1| def test(a, *, *):
^
You can only use `*` once in a function definition.
(90) def: *
used twice¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_star_used_only_once_2.py", line 1
def test(a, *arg, *other):
^
SyntaxError: * argument may appear only once
You can only use `*` once in a function definition.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_star_used_only_once_2.py'
at the location indicated.
1| def test(a, *arg, *other):
^
You can only use `*` once in a function definition.
You have used it twice, with `*arg` and `*other`.
(91) def: *
after **
¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_star_after_2star.py", line 1
def test(**kw, *arg):
^
SyntaxError: arguments cannot follow var-keyword argument
You can only use `*` once in a function definition.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_star_after_2star.py'
at the location indicated.
1| def test(**kw, *arg):
^
`*arg` must appear before `**kw`.
(92) def: *
after **
¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_star_after_2star_2.py", line 1
def test(**kw, *):
^
SyntaxError: arguments cannot follow var-keyword argument
You can only use `*` once in a function definition.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_star_after_2star_2.py'
at the location indicated.
1| def test(**kw, *):
^
`**kw` must appear after the `*` operator.
(93) Single string used as arg in function def¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_string_as_arg.py", line 1
def f("1"):
^^^
SyntaxError: invalid syntax
You cannot use strings as function arguments.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_string_as_arg.py'
at the location indicated.
1| def f("1"):
^^^
You used a string as an argument when defining a function.
You can only use identifiers (variable names) as function arguments.
(94) def: tuple as function argument¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_tuple_as_arg_1.py", line 1
def test((a, b), c):
^^^^^^
SyntaxError: Function parameters cannot be parenthesized
You cannot have explicit tuples as function arguments.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_tuple_as_arg_1.py'
at the location indicated.
1| def test((a, b), c):
^^^^^^
You cannot have explicit tuples as function arguments.
You can only use identifiers (variable names) as function arguments.
Assign any tuple to a parameter and unpack it
within the body of the function.
(95) def: tuple as function argument - 2¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\def_tuple_as_arg_2.py", line 1
def test(a, (b, c)):
^^^^^^
SyntaxError: Function parameters cannot be parenthesized
You cannot have explicit tuples as function arguments.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\def_tuple_as_arg_2.py'
at the location indicated.
1| def test(a, (b, c)):
^^^^^^
You cannot have explicit tuples as function arguments.
You can only use identifiers (variable names) as function arguments.
Assign any tuple to a parameter and unpack it
within the body of the function.
(96) Deleting star expression - 1¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\del_paren_star_1.py", line 1
del (*x)
^^
SyntaxError: cannot use starred expression here
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\del_paren_star_1.py'
at the location indicated.
1| del (*x)
^^
The star operator `*` is interpreted to mean that
iterable unpacking is to be used to assign a name
to each item of an iterable, which does not make sense here.
You can only delete names of objects, or items in mutable containers
such as `list`, `set`, or `dict`.
(97) Deleting star expression - 2¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\del_paren_star_2.py", line 1
del (*x,)
^^
SyntaxError: cannot delete starred
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\del_paren_star_2.py'
at the location indicated.
1| del (*x,)
^^
The star operator `*` is interpreted to mean that
iterable unpacking is to be used to assign a name
to each item of an iterable, which does not make sense here.
You can only delete names of objects, or items in mutable containers
such as `list`, `set`, or `dict`.
(98) Cannot delete a constant¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\delete_constant_keyword.py", line 1
del True
^^^^
SyntaxError: cannot delete True
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\delete_constant_keyword.py'
at the location indicated.
1| del True
^^^^
You cannot delete the constant `True`.
You can only delete names of objects, or items in mutable containers
such as `list`, `set`, or `dict`.
(99) Cannot delete expression¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\delete_expression.py", line 1
del a.b.c[0] + 2
^^^^^^^^^^^^
SyntaxError: cannot delete expression
You can only delete names of objects, or items in mutable containers
such as `list`, `set`, or `dict`.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\delete_expression.py'
at the location indicated.
1| del a.b.c[0] + 2
^^^^^^^^^^^^
You cannot delete the expression `a.b.c[0] + 2`.
You can only delete names of objects, or items in mutable containers
such as `list`, `set`, or `dict`.
(100) Cannot delete function call¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\delete_function_call.py", line 5
del f(a)
^^^^
SyntaxError: cannot delete function call
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\delete_function_call.py'
at the location indicated.
5| del f(a)
^^^^
You attempted to delete a function call
del f(a)
instead of deleting the function's name
del f
(101) Cannot delete named expression¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\delete_named_expression.py", line 1
del (a := 5)
^^^^^^
SyntaxError: cannot delete named expression
You can only delete names of objects, or items in mutable containers
such as `list`, `set`, or `dict`.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\delete_named_expression.py'
at the location indicated.
1| del (a := 5)
^^^^^^
You cannot delete the named expression `(a := 5)`.
You can only delete names of objects, or items in mutable containers
such as `list`, `set`, or `dict`.
(102) Delete only names or items¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\delete_names_or_items.py", line 1
del a += b
^^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\delete_names_or_items.py'
at the location indicated.
1| del a += b
^^
You can only delete names of objects, or items in mutable containers
such as `list`, `set`, or `dict`.
(103) Deleting string literal¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\delete_string_literal.py", line 1
del "Hello world!"
^^^^^^^^^^^^^^
SyntaxError: cannot delete literal
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\delete_string_literal.py'
at the location indicated.
1| del "Hello world!"
^^^^^^^^^^^^^^
You cannot delete the literal `"Hello world!"`.
You can only delete names of objects, or items in mutable containers
such as `list`, `set`, or `dict`.
(104) Value missing in dict - 1¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\dict_value_missing_1.py", line 1
a = {1:2, 3}
^
SyntaxError: ':' expected after dictionary key
Did you forget to write a dict value?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\dict_value_missing_1.py'
at the location indicated.
1| a = {1:2, 3}
^
It looks like the error occurred as you were writing a Python dict.
Perhaps you wrote a dict key without writing the corresponding value.
(105) Value missing in dict - 2¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\dict_value_missing_2.py", line 2
a = {1:2, 3:}
^
SyntaxError: expression expected after dictionary key and ':'
Did you forget to write a dict value?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\dict_value_missing_2.py'
at the location indicated.
2| a = {1:2, 3:}
^
It looks like the error occurred as you were writing a Python dict.
Perhaps you forgot to write a value after a colon.
(106) Value missing in dict - 3¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\dict_value_missing_3.py", line 3
a = {1:2, 3, 4:5}
^
SyntaxError: ':' expected after dictionary key
Did you forget to write a dict value?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\dict_value_missing_3.py'
at the location indicated.
3| a = {1:2, 3, 4:5}
^
It looks like the error occurred as you were writing a Python dict.
Perhaps you wrote a dict key without writing the corresponding value.
(107) Value missing in dict - 4¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\dict_value_missing_4.py", line 4
a = {1:2, 3:, 4:5}
^
SyntaxError: expression expected after dictionary key and ':'
Did you forget to write a dict value?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\dict_value_missing_4.py'
at the location indicated.
4| a = {1:2, 3:, 4:5}
^
It looks like the error occurred as you were writing a Python dict.
Perhaps you forgot to write a value after a colon.
(108) Different operators in a row¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\different_operators_in_a_row.py", line 1
3 */ 4
^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\different_operators_in_a_row.py'
at the location indicated.
1| 3 */ 4
^^
You cannot have these two operators, `*` and `/`,
following each other. Perhaps you wrote one of them by mistake
or forgot to write something between them.
(109) Dot followed by parenthesis¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\dot_before_paren.py", line 3
print(len.('hello'))
^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\dot_before_paren.py'
at the location indicated.
3| print(len.('hello'))
^
You cannot have a dot `.` followed by `(`.
Perhaps you need to replace the dot by a comma.
(110) Extra token¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\duplicate_token.py", line 1
print(1 , , 2)
^
SyntaxError: invalid syntax
Did you write `,` twice by mistake?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\duplicate_token.py'
at the location indicated.
1| print(1 , , 2)
^
I am guessing that you wrote `,` twice in a row by mistake.
If that is the case, you need to remove the second one.
(111) elif with no matching if¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\elif_not_matching_if.py", line 3
elif True:
^^^^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\elif_not_matching_if.py'
at the location indicated.
3| elif True:
^^^^
The `elif` keyword does not begin a code block that matches
an `if` block, possibly because `elif` is not indented correctly.
(112) Ellipsis written with extra dot¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\ellipsis_extra_dot.py", line 2
....
^
SyntaxError: invalid syntax
Did you mean to write `...`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\ellipsis_extra_dot.py'
at the location indicated.
2| ....
^
It looks like you meant to write `...` but added an extra `.` by mistake.
(113) else with no matching statement¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\else_no_matching_statement.py", line 3
else:
^^^^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\else_no_matching_statement.py'
at the location indicated.
3| else:
^^^^
The `else` keyword does not begin a code block that matches
a valid code block, possibly because `else` is not indented correctly.
(114) Write elif, not else if¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\else_if_instead_of_elif.py", line 5
else if True:
^^
SyntaxError: expected ':'
Perhaps you meant to write `elif`.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\else_if_instead_of_elif.py'
at the location indicated.
5| else if True:
^^^^^^^
Python told us that it expected a colon at the position indicated.
However, adding a colon or replacing something else by a colon
would not fix the problem.
You likely meant to use Python's `elif` keyword
but wrote `else if` instead.
(115) Write elif, not elseif¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\elseif_instead_of_elif.py", line 5
elseif True:
^^^^
SyntaxError: invalid syntax
Perhaps you meant to write `elif`.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\elseif_instead_of_elif.py'
at the location indicated.
5| elseif True:
^^^^^^
You likely meant to use Python's `elif` keyword
but wrote `elseif` instead.
(116) EOL while scanning string literal¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\eol_string_literal.py", line 3
alphabet = 'abc
^
SyntaxError: unterminated string literal (detected at line 3)
Did you forget a closing quote?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\eol_string_literal.py'
at the location indicated.
3| alphabet = 'abc
^
You started writing a string with a single or double quote
but never ended the string with another quote on that line.
(117) Used equal sign instead of colon¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\equal_sign_instead_of_colon.py", line 4
ages = {'Alice'=22, 'Bob'=24}
^^^^^^^
SyntaxError: cannot assign to literal here. Maybe you meant '==' instead of '='?
You can only assign objects to identifiers (variable names).
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\equal_sign_instead_of_colon.py'
at the location indicated.
4| ages = {'Alice'=22, 'Bob'=24}
^^^^^^^
You wrote an expression like
'Alice' = variable_name
where `'Alice'`, on the left-hand side of the equal sign,
is or includes an actual object of type `str`
and is not simply the name of a variable.
You can only assign objects to identifiers (variable names).
It is possible that you used an equal sign `=` instead of a colon `:`
to assign values to keys in a dict.
(118) Parens around multiple exceptions¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\except_multiple_exceptions.py", line 3
except NameError, ValueError as err:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: multiple exception types must be parenthesized
Did you forget parentheses?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\except_multiple_exceptions.py'
at the location indicated.
3| except NameError, ValueError as err:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I am guessing that you wanted to use an `except` statement
with multiple exception types. If that is the case, you must
surround them with parentheses.
(119) except with no matching try¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\except_no_try.py", line 1
except Exception:
^^^^^^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\except_no_try.py'
at the location indicated.
1| except Exception:
^^^^^^
The `except` keyword does not begin a code block that matches
a `try` block, possibly because `except` is not indented correctly.
(120) except or finally missing¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\except_or_finally.py", line 3
something:
^^^^^^^^^
SyntaxError: expected 'except' or 'finally' block
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\except_or_finally.py'
at the location indicated.
3| something:
^^^^^^^^^
You wrote a `try` block which did not include an `except` nor a `finally` block.
Perhaps you meant to write either
except:
or
finally:
(121) Extra token¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\extra_token.py", line 1
print(1 / 2) ==
^
SyntaxError: invalid syntax
Did you write `==` by mistake?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\extra_token.py'
at the location indicated.
1| print(1 / 2) ==
^^
I am guessing that you wrote `==` by mistake.
Removing it and writing `print(1 / 2)` seems to fix the error.
(122) Binary f-string not allowed¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\f_string_binary.py", line 1
greet = bf"Hello {name}"
^^^^^^^^^^^^^^
SyntaxError: invalid syntax
`bf` is an illegal string prefix.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\f_string_binary.py'
at the location indicated.
1| greet = bf"Hello {name}"
^^^^^^^^^^^^^^
I am guessing that you wanted a binary f-string;
this is not allowed.
(123) f-string: closing } not allowed¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\f_string_curly_not_allowed.py", line 1
f"ab}"
^
SyntaxError: f-string: single '}' is not allowed
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\f_string_curly_not_allowed.py'
at the location indicated.
1| f"ab}"
^^^^^^
You have written an f-string which has an unmatched `}`.
If you want to print a single `}`, you need to write `}}` in the f-string;
otherwise, you need to add an opening `{`.
(124) f-string: missing closing }¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\f_string_expected_curly.py", line 1
f"{ab"
^
SyntaxError: f-string: expecting '}'
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\f_string_expected_curly.py'
at the location indicated.
1| f"{ab"
^^^^^^
You have written an f-string which has an unmatched `{`.
If you want to print a single `{`, you need to write `{{` in the f-string;
otherwise, you need to add a closing `}`.
(125) f-string: unterminated string¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\f_string_unterminated.py", line 4
print(f"Bob is {age['Bob]} years old.")
^
SyntaxError: f-string: unterminated string
Perhaps you forgot a closing quote.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\f_string_unterminated.py'
at the location indicated.
4| print(f"Bob is {age['Bob]} years old.")
^
Inside the f-string `f"Bob is {age['Bob]} years old."`,
you have another string, which starts with either a
single quote (') or double quote ("), without a matching closing one.
(126) f-string with backslash¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\f_string_with_backslash.py", line 2
print(f"{'\n'.join(names)}")
^
SyntaxError: f-string expression part cannot include a backslash
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\f_string_with_backslash.py'
at the location indicated.
2| print(f"{'\n'.join(names)}")
^
You have written an f-string whose content `{...}`
includes a backslash; this is not allowed.
Perhaps you can replace the part that contains a backslash by
some variable. For example, suppose that you have an f-string like:
f"{... 'hello\n' ...}"
you could write this as
hello = 'hello\n'
f"{... hello ...}"
(127) finally with no matching try¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\finally_no_try.py", line 1
finally:
^^^^^^^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\finally_no_try.py'
at the location indicated.
1| finally:
^^^^^^^
The `finally` keyword does not begin a code block that matches
a `try` block, possibly because `finally` is not indented correctly.
(128) Missing terms in for statement¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\for_missing_terms.py", line 1
for:
^
SyntaxError: invalid syntax
A `for` loop requires at least 3 more terms.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\for_missing_terms.py'
at the location indicated.
1| for:
^
A `for` loop is an iteration over a sequence:
for element in sequence:
...
(129) Not a chance!¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\future_braces.py", line 1
from __future__ import braces
^
SyntaxError: not a chance
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\future_braces.py'
at the location indicated.
1| from __future__ import braces
^^^^
I suspect you wrote `from __future__ import braces` following
someone else's suggestion. This will never work.
Unlike other programming languages, Python's code block are defined by
their indentation level, and not by using some curly braces, like `{...}`.
(130) Do not import * from __future__¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\future_import_star.py", line 1
from __future__ import *
^
SyntaxError: future feature * is not defined
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\future_import_star.py'
at the location indicated.
1| from __future__ import *
^^^^
When using a `from __future__ import` statement,
you must import specific named features.
The available features are `nested_scopes,
generators,
division,
absolute_import,
with_statement,
print_function,
unicode_literals,
barry_as_FLUFL,
generator_stop,
annotations`.
(131) __future__ at beginning¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\future_must_be_first.py", line 3
from __future__ import generators
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: from __future__ imports must occur at the beginning of the file
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\future_must_be_first.py'
at the location indicated.
3| from __future__ import generators
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
A `from __future__ import` statement changes the way Python
interprets the code in a file.
It must appear at the beginning of the file.
(132) Typo in __future__¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\future_typo.py", line 1
from __future__ import divisio
^
SyntaxError: future feature divisio is not defined
Did you mean `division`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\future_typo.py'
at the location indicated.
1| from __future__ import divisio
^^^^
Instead of `divisio`, perhaps you meant to import `division`.
(133) Unknown feature in __future__¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\future_unknown.py", line 1
from __future__ import something
^
SyntaxError: future feature something is not defined
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\future_unknown.py'
at the location indicated.
1| from __future__ import something
^^^^
`something` is not a valid feature of module `__future__`.
The available features are `nested_scopes,
generators,
division,
absolute_import,
with_statement,
print_function,
unicode_literals,
barry_as_FLUFL,
generator_stop,
annotations`.
(134) Parenthesis around generator expression¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\generator_expression_parens.py", line 6
f(x for x in L, 1)
^^^^^^^^^^^^
SyntaxError: Generator expression must be parenthesized
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\generator_expression_parens.py'
at the location indicated.
6| f(x for x in L, 1)
^^^^^^^^^^^^
You are using a generator expression, something of the form
x for x in thing
You must add parentheses enclosing that expression.
(135) Space between names¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\hyphen_instead_of_underscore.py", line 4
a-b = 2
^^^
SyntaxError: cannot assign to expression here. Maybe you meant '==' instead of '='?
Did you mean `a_b`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\hyphen_instead_of_underscore.py'
at the location indicated.
4| a-b = 2
^^^
You wrote an expression that includes some mathematical operations
on the left-hand side of the equal sign which should be
only used to assign a value to a variable.
Perhaps you meant to write `a_b` instead of `a-b`
(136) Missing condition in if statement¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\if_missing_condition.py", line 1
if:
^
SyntaxError: invalid syntax
You forgot to add a condition.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\if_missing_condition.py'
at the location indicated.
1| if:
^
An `if` statement requires a condition:
if condition:
...
(137) use j instead of i¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\imaginary_i.py", line 3
a = 3.0i
^
SyntaxError: invalid decimal literal
Did you mean `3.0j`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\imaginary_i.py'
at the location indicated.
3| a = 3.0i
^^^^
Python tells us that you have written an invalid number.
However, I think that the problem might be the following.
Perhaps you thought that `i` could be used to represent
the square root of `-1`. In Python, the symbol used for this is `j`
and the complex part is written as `some_number` immediately
followed by `j`, with no spaces in between.
Perhaps you meant to write `3.0j`.
(138) Import inversion: import X from Y¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\import_from.py", line 3
import pen from turtle
^^^^
SyntaxError: invalid syntax
Did you mean `from turtle import pen`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\import_from.py'
at the location indicated.
3| import pen from turtle
^^^^^^ ^^^^
You wrote something like
import pen from turtle
instead of
from turtle import pen
(139) IndentationError: expected an indented block¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\indentation_error_1.py", line 4
pass
^^^^
IndentationError: expected an indented block after 'if' statement on line 3
An `IndentationError` occurs when a given line of code is
not indented (aligned vertically with other lines) as expected.
Python could not understand the code in the file
'TESTS:\syntax\indentation_error_1.py'
at the location indicated.
4| pass
^^^^
Line `4` identified above was expected to begin a new indented block.
(140) IndentationError: unexpected indent¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\indentation_error_2.py", line 4
pass
^
IndentationError: unexpected indent
An `IndentationError` occurs when a given line of code is
not indented (aligned vertically with other lines) as expected.
Python could not understand the code in the file
'TESTS:\syntax\indentation_error_2.py'
at the location indicated.
4| pass
^^^^
Line `4` identified above is more indented than expected.
(141) IndentationError: unindent does not match …¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\indentation_error_3.py", line 5
pass
^
IndentationError: unindent does not match any outer indentation level
An `IndentationError` occurs when a given line of code is
not indented (aligned vertically with other lines) as expected.
Python could not understand the code in the file
'TESTS:\syntax\indentation_error_3.py'
at the location indicated.
5| pass
^^^^
Line `5` identified above is less indented than expected.
(142) IndentationError: missing continuation line¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\indentation_error_4.py", line 6
"c"
^
IndentationError: unexpected indent
An `IndentationError` occurs when a given line of code is
not indented (aligned vertically with other lines) as expected.
Python could not understand the code in the file
'TESTS:\syntax\indentation_error_4.py'
at the location indicated.
6| "c"
^^^
Line `6` identified above is more indented than expected.
However, line 6, which is identified as having a problem,
consists of a single string which is also the case
for the preceding line.
Perhaps you meant to include a continuation character, `\`,
at the end of line 5.
(143) Forgot ‘o’ for octal¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\integer_with_leading_zero_1.py", line 1
x = 01
^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
Did you mean `0o1`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\integer_with_leading_zero_1.py'
at the location indicated.
1| x = 01
^
Perhaps you meant to write the octal number `0o1`
and forgot the letter 'o', or perhaps you meant to write
a decimal integer and did not know that it could not start with zeros.
(144) Integer with leading zeros¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\integer_with_leading_zero_2.py", line 1
x = 000_123_456
^^^^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
Did you mean `123_456`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\integer_with_leading_zero_2.py'
at the location indicated.
1| x = 000_123_456
^^^
Perhaps you meant to write the integer `123_456`
and did not know that it could not start with zeros.
(145) Invalid character in identifier¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\invalid_character_in_identifier.py", line 6
🤖 = 'Reeborg'
^
SyntaxError: invalid character '🤖' (U+1F916)
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\invalid_character_in_identifier.py'
at the location indicated.
6| 🤖 = 'Reeborg'
^
Python indicates that you used the unicode character `🤖`
which is not allowed.
(146) Invalid decimal literal - 1¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\invalid_decimal_literal1.py", line 1
a = 1f
^
SyntaxError: invalid decimal literal
Perhaps you forgot a multiplication operator, `1 * f`.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\invalid_decimal_literal1.py'
at the location indicated.
1| a = 1f
^^
Python tells us that you have written an invalid number.
However, I think that the problem might be the following.
Valid names cannot begin with a number.
Perhaps you forgot a multiplication operator, `1 * f`.
(147) Invalid encoding¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\invalid_encoding.py", line 2, in <module>
compile(source, filename="example.py", mode="exec")
File "TESTS:\example.py", line 0
SyntaxError: encoding problem: utf8 with BOM
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\example.py'
The encoding of the file was not valid.
(148) Invalid hexadecimal number¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\invalid_hexadecimal.py", line 3
a = 0x123g4
^
SyntaxError: invalid hexadecimal literal
Did you made a mistake in writing an hexadecimal integer?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\invalid_hexadecimal.py'
at the location indicated.
3| a = 0x123g4
^^^^^^^
It looks like you used an invalid character (`g`) in an hexadecimal number.
Hexadecimal numbers are base 16 integers that use the symbols `0` to `9`
to represent values 0 to 9, and the letters `a` to `f` (or `A` to `F`)
to represent values 10 to 15.
In Python, hexadecimal numbers start with either `0x` or `0X`,
followed by the characters used to represent the value of that integer.
(149) Valid names cannot begin with a number¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\invalid_identifier.py", line 3
36abc = 3
^
SyntaxError: invalid decimal literal
Valid names cannot begin with a number.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\invalid_identifier.py'
at the location indicated.
3| 36abc = 3
^^^
Python tells us that you have written an invalid number.
However, I think that the problem might be the following.
Valid names cannot begin with a number.
(150) Valid names cannot begin with a number - 2¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\invalid_identifier_2.py", line 3
tau = 2pi
^
SyntaxError: invalid decimal literal
Perhaps you forgot a multiplication operator, `2 * pi`.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\invalid_identifier_2.py'
at the location indicated.
3| tau = 2pi
^^^
Python tells us that you have written an invalid number.
However, I think that the problem might be the following.
Valid names cannot begin with a number.
Perhaps you forgot a multiplication operator, `2 * pi`.
(151) Valid names cannot begin with a number - 3¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\invalid_identifier_3.py", line 1
3job # could be entered in a repl
^
SyntaxError: invalid imaginary literal
Perhaps you forgot a multiplication operator, `3 * job`.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\invalid_identifier_3.py'
at the location indicated.
1| 3job # could be entered in a repl
^^^^
Valid names cannot begin with a number.
Perhaps you forgot a multiplication operator, `3 * job`.
[Note: `3j * ob` would also be valid
since `3j` is a complex number.]
(152) Valid names cannot begin with a number - 4¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\invalid_identifier_4.py", line 1
3job = 1
^
SyntaxError: invalid imaginary literal
Valid names cannot begin with a number.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\invalid_identifier_4.py'
at the location indicated.
1| 3job = 1
^^^
Valid names cannot begin with a number.
(153) Valid names cannot begin with a number - 5¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\invalid_identifier_5.py", line 1
print(42java)
^
SyntaxError: invalid imaginary literal
Perhaps you forgot a multiplication operator, `42 * java`.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\invalid_identifier_5.py'
at the location indicated.
1| print(42java)
^^^^
Valid names cannot begin with a number.
Perhaps you forgot a multiplication operator, `42 * java`.
[Note: `42j * ava` would also be valid
since `42j` is a complex number.]
(154) Keyword can’t be an expression¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\invalid_keyword_argument.py", line 7
a = dict('key'=1)
^^^^^^
SyntaxError: expression cannot contain assignment, perhaps you meant "=="?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\invalid_keyword_argument.py'
at the location indicated.
7| a = dict('key'=1)
^^^^^^
You likely called a function with a named argument:
a_function(invalid=something)
where `invalid` is not a valid variable name in Python
either because it starts with a number, or is a string,
or contains a period, etc.
(155) Named argument can’t be a Python keyword¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\invalid_keyword_argument_2.py", line 7
a = dict(True=1)
^^^^^
SyntaxError: cannot assign to True
You cannot assign a value to `True`.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\invalid_keyword_argument_2.py'
at the location indicated.
7| a = dict(True=1)
^^^^^
`True` is a constant in Python; you cannot assign it a different value.
(156) Invalid non printable character¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\invalid_non_printable_char.py", line 2, in <module>
eval(s)
File "<string>", line 1
print("Hello")
^
SyntaxError: invalid non-printable character U+0017
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'<string>'
at the location indicated.
1| print("Hello")
^
Your code contains the invalid non-printable character '\x17'.
(157) Invalid octal number¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\invalid_octal.py", line 3
b = 0O1876
^
SyntaxError: invalid digit '8' in octal literal
Did you made a mistake in writing an octal integer?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\invalid_octal.py'
at the location indicated.
3| b = 0O1876
^^^
It looks like you used an invalid character (`8`) in an octal number.
Octal numbers are base 8 integers that only use the symbols `0` to `7`
to represent values.
In Python, octal numbers start with either `0o` or `0O`,
(the digit zero followed by the letter `o`)
followed by the characters used to represent the value of that integer.
(158) Inverted operators 1¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\inverted_operators.py", line 1
a =< 3
^
SyntaxError: invalid syntax
Did you write operators in an incorrect order?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\inverted_operators.py'
at the location indicated.
1| a =< 3
^^
It looks like you wrote two operators (`=` and `<`)
in the wrong order: `=<` instead of `<=`.
(159) Inverted operators 2¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\inverted_operators_2.py", line 1
a =<* 3
^
SyntaxError: invalid syntax
Did you write operators in an incorrect order?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\inverted_operators_2.py'
at the location indicated.
1| a =<* 3
^^
It looks like you wrote two operators (`=` and `<`)
in the wrong order: `=<` instead of `<=`.
However, making such a change would still not correct
all the syntax errors in the code you wrote.
(160) Iteration variable unpacking in comprehension¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\iteration_unpacking_in_comprehension.py", line 1
[*x for x in xs]
^^
SyntaxError: iterable unpacking cannot be used in comprehension
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\iteration_unpacking_in_comprehension.py'
at the location indicated.
1| [*x for x in xs]
^^
You cannot use the `*` operator to unpack the iteration variable
in a comprehension.
The following statement has no syntax error:
[x for x in xs]
(161) Keyword arg only once in function call¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\keyword_arg_repeated.py", line 4
f(ad=1, ad=2)
^^^^
SyntaxError: keyword argument repeated: ad
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\keyword_arg_repeated.py'
at the location indicated.
4| f(ad=1, ad=2)
^^^^
You have called a function repeating the same keyword argument (`ad`).
Each keyword argument should appear only once in a function call.
(162) Keyword as attribute¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\keyword_as_attribute.py", line 12
a.pass = 2
^^^^
SyntaxError: invalid syntax
`pass` cannot be used as an attribute.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\keyword_as_attribute.py'
at the location indicated.
12| a.pass = 2
^^^^
You cannot use the Python keyword `pass` as an attribute.
(163) lambda with parentheses around arguments¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\lambda_with_parens.py", line 2
x = lambda (a, b): a + b
^^^^^^
SyntaxError: Lambda expression parameters cannot be parenthesized
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\lambda_with_parens.py'
at the location indicated.
2| x = lambda (a, b): a + b
^^^^^^
`lambda` does not allow parentheses around its arguments.
This was allowed in Python 2 but it not allowed in Python 3.
(164) lambda with tuple as argument¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\lambda_with_tuple_argument.py", line 2
x = lambda a, (b, c): a + b + b
^^^^^^
SyntaxError: Lambda expression parameters cannot be parenthesized
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\lambda_with_tuple_argument.py'
at the location indicated.
2| x = lambda a, (b, c): a + b + b
^^^^^^
You cannot have explicit tuples as arguments.
Assign any tuple to a parameter and unpack it
within the body of the function.
(165) Assign to literal in for loop¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\literal_in_for_loop.py", line 1
for "char" in "word":
^^^^^^
SyntaxError: cannot assign to literal
You can only assign objects to identifiers (variable names).
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\literal_in_for_loop.py'
at the location indicated.
1| for "char" in "word":
^^^^^^
A for loop must have the form:
for ... in sequence:
where `...` must contain only identifiers (variable names)
and not literals like `"char"`.
(166) IndentationError/SyntaxError depending on version¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\missing_code_block.py", line 4
IndentationError: expected an indented block after 'for' statement on line 3
An `IndentationError` occurs when a given line of code is
not indented (aligned vertically with other lines) as expected.
Python could not understand the code in the file
'TESTS:\syntax\missing_code_block.py'
at the location indicated.
3| for i in range(10):
-->4|
^
Line `4` identified above was expected to begin a new indented block.
(167) IndentationError/SyntaxError depending on version - 2¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\missing_code_block_2.py", line 6
IndentationError: expected an indented block after 'for' statement on line 3
An `IndentationError` occurs when a given line of code is
not indented (aligned vertically with other lines) as expected.
Python could not understand the code in the file
'TESTS:\syntax\missing_code_block_2.py'
3| for i in "test":
4|
Line `6` identified above was expected to begin a new indented block.
(168) Missing colon - if¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\missing_colon_if.py", line 3
if True
^
SyntaxError: expected ':'
Did you forget a colon `:`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\missing_colon_if.py'
at the location indicated.
3| if True
^
You wrote a statement beginning with
`if` but forgot to add a colon `:` at the end.
(169) Missing colon - while¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\missing_colon_while.py", line 3
while True # a comment
^^^^^^^^^^^
SyntaxError: expected ':'
Did you forget a colon `:`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\missing_colon_while.py'
at the location indicated.
3| while True # a comment
^
You wrote a `while` loop but
forgot to add a colon `:` at the end
(170) Missing comma in a dict¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\missing_comma_in_dict.py", line 4
'b': 2
^-->
SyntaxError: invalid syntax. Perhaps you forgot a comma?
Did you forget a comma?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\missing_comma_in_dict.py'
at the location indicated.
3| a = {'a': 1,
-->4| 'b': 2
^-->
-->5| 'c': 3,
^^^
6| }
Python indicates that the error is caused by `'c'` written immediately after `2`.
It is possible that you forgot a comma between items in a set or dict
at the position indicated by ^.
Perhaps you meant
a = {'a': 1,
'b': 2,
^
'c': 3,
}
(171) Missing comma between strings in a dict¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\missing_comma_in_dict_2.py", line 4
'c': '3',
^
SyntaxError: invalid syntax
Did you forget a comma?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\missing_comma_in_dict_2.py'
at the location indicated.
2| a = {'a': '1',
3| 'b': '2'
-->4| 'c': '3',
^
5| }
I am guessing that you forgot a comma between two strings
when defining a dict.
```
a = {'a': '1',
'b': '2',
^
'c': '3',
}
```
(172) Missing comma in a list¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\missing_comma_in_list.py", line 3
a = [1, 2 3]
^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
Did you forget something between `2` and `3`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\missing_comma_in_list.py'
at the location indicated.
3| a = [1, 2 3]
^^^^
Python indicates that the error is caused by `3` written immediately after `2`.
It is possible that you forgot a comma between items in a list
at the position indicated by ^.
Perhaps you meant to insert an operator like `+, -, *`
between `2` and `3`.
The following lines of code would not cause any `SyntaxError`:
a = [1, 2, 3]
a = [1, 2 + 3]
a = [1, 2 - 3]
a = [1, 2 * 3]
Note: these are just some of the possible choices and that
some of them might raise other types of exceptions.
(173) Missing comma in a set¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\missing_comma_in_set.py", line 3
a = {1, 2 3}
^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
Did you forget something between `2` and `3`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\missing_comma_in_set.py'
at the location indicated.
3| a = {1, 2 3}
^^^^
Python indicates that the error is caused by `3` written immediately after `2`.
It is possible that you forgot a comma between items in a set or dict
at the position indicated by ^.
Perhaps you meant to insert an operator like `+, -, *`
between `2` and `3`.
The following lines of code would not cause any `SyntaxError`:
a = {1, 2, 3}
a = {1, 2 + 3}
a = {1, 2 - 3}
a = {1, 2 * 3}
Note: these are just some of the possible choices and that
some of them might raise other types of exceptions.
(174) Missing comma in a tuple¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\missing_comma_in_tuple.py", line 3
a = (1, 2 3)
^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
Did you forget something between `2` and `3`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\missing_comma_in_tuple.py'
at the location indicated.
3| a = (1, 2 3)
^^^^
Python indicates that the error is caused by `3` written immediately after `2`.
It is possible that you forgot a comma between items in a tuple,
or between function arguments,
at the position indicated by ^.
Perhaps you meant to insert an operator like `+, -, *`
between `2` and `3`.
The following lines of code would not cause any `SyntaxError`:
a = (1, 2, 3)
a = (1, 2 + 3)
a = (1, 2 - 3)
a = (1, 2 * 3)
Note: these are just some of the possible choices and that
some of them might raise other types of exceptions.
(175) For loop missing ‘in’ operator¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\missing_in_with_for.py", line 1
for x range(4):
^^^^^
SyntaxError: invalid syntax
Did you forget to write `in`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\missing_in_with_for.py'
at the location indicated.
1| for x range(4):
^^^^^
It looks as though you forgot to use the keyword `in`
as part of a `for` statement. Perhaps you meant:
for x in range(4):
(176) Missing parenthesis for range¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\missing_parens_for_range.py", line 1
for i in range 3:
^
SyntaxError: invalid syntax
Did you forget to write parenthesis?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\missing_parens_for_range.py'
at the location indicated.
1| for i in range 3:
^
It looks as though you forgot to use to use parenthesis with `range`.
Perhaps you meant:
for i in range( 3):
(177) Misspelled Python keyword¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\misspelled_keyword.py", line 2
is i in range(3):
^^
SyntaxError: invalid syntax
Did you mean `if i in range(3):`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\misspelled_keyword.py'
at the location indicated.
2| is i in range(3):
^^
Perhaps you meant to write `if` and made a typo.
The correct line might be `if i in range(3):`
(178) Name is global and nonlocal¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\name_is_global_and_nonlocal.py", line 7
global xy
^^^^^^^^^
SyntaxError: name 'xy' is nonlocal and global
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\name_is_global_and_nonlocal.py'
at the location indicated.
7| global xy
^^^^^^^^^
You declared `xy` as being both a global and nonlocal variable.
A variable can be global, or nonlocal, but not both at the same time.
(179) Name is parameter and nonlocal¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\name_is_param_and_nonlocal.py", line 5
nonlocal x
^^^^^^^^^^
SyntaxError: name 'x' is parameter and nonlocal
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\name_is_param_and_nonlocal.py'
at the location indicated.
5| nonlocal x
^^^^^^^^^^
You used `x` as a parameter for a function
before declaring it also as a nonlocal variable:
`x` cannot be both at the same time.
(180) nonlocal variable not found¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\no_binding_for_nonlocal.py", line 5
nonlocal ab
^^^^^^^^^^^
SyntaxError: no binding for nonlocal 'ab' found
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\no_binding_for_nonlocal.py'
at the location indicated.
5| nonlocal ab
^^^^^^^^^^^
You declared the variable `ab` as being a
nonlocal variable but it cannot be found.
(181) nonlocal variable not found at module level¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\nonlocal_at_module.py", line 4
nonlocal cd
^^^^^^^^^^^
SyntaxError: nonlocal declaration not allowed at module level
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\nonlocal_at_module.py'
at the location indicated.
4| nonlocal cd
^^^^^^^^^^^
You used the nonlocal keyword at a module level.
The nonlocal keyword refers to a variable inside a function
given a value outside that function.
(182) Same operator twice in a row¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\operator_twice_in_a_row.py", line 1
4****5
^^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\operator_twice_in_a_row.py'
at the location indicated.
1| 4****5
^^^^
You cannot have write the same operator, `**`, twice in a row.
Perhaps you wrote one of them by mistake
or forgot to write something between them.
(183) Using pip from interpreter¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\pip_install_1.py", line 2
pip install friendly
^^^^^^^
SyntaxError: invalid syntax
Pip cannot be used in a Python interpreter.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\pip_install_1.py'
at the location indicated.
2| pip install friendly
^^^^^^^
It looks as if you are attempting to use pip to install a module.
`pip` is a command that needs to run in a terminal,
not from a Python interpreter.
(184) Using pip from interpreter 2¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\pip_install_2.py", line 2
python -m pip install friendly
^^^
SyntaxError: invalid syntax
Pip cannot be used in a Python interpreter.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\pip_install_2.py'
at the location indicated.
2| python -m pip install friendly
^^^
It looks as if you are attempting to use pip to install a module.
`pip` is a command that needs to run in a terminal,
not from a Python interpreter.
(185) print is a function¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\print_is_a_function.py", line 2
print 'hello'
^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
Did you mean `print('hello')`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\print_is_a_function.py'
at the location indicated.
2| print 'hello'
^^^^^^^^^^^^^
Perhaps you need to type
print('hello')
In older version of Python, `print` was a keyword.
Now, `print` is a function; you need to use parentheses to call it.
(186) print is a function 2¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\print_is_a_function_2.py", line 2
print len('hello')
^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
Did you mean `print(len('hello'))`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\print_is_a_function_2.py'
at the location indicated.
2| print len('hello')
^^^^^^^^^^^^^^^^^^
Perhaps you need to type
print(len('hello'))
In older version of Python, `print` was a keyword.
Now, `print` is a function; you need to use parentheses to call it.
(187) print is a function 3¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\print_is_a_function_3.py", line 1
print """This is a very long string which results in a very long error message."""
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
Did you mean `print(...)`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\print_is_a_function_3.py'
at the location indicated.
1| print """This is a very long string which results in a very long error message."""
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Perhaps you need to type
print(...)
In older version of Python, `print` was a keyword.
Now, `print` is a function; you need to use parentheses to call it.
(188) print is a function 4¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\print_is_a_function_4.py", line 2
print len("""This is a long string
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-->
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
Did you mean `print(...)`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\print_is_a_function_4.py'
at the location indicated.
-->2| print len("""This is a long string
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3| that spans multiple lines.""")
Perhaps you need to type
print(...)
In older version of Python, `print` was a keyword.
Now, `print` is a function; you need to use parentheses to call it.
(189) print is a function 5¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\print_is_a_function_5.py", line 2
print len('This is a long string that fits on a single line.')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
Did you mean `print(...)`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\print_is_a_function_5.py'
at the location indicated.
2| print len('This is a long string that fits on a single line.')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Perhaps you need to type
print(...)
In older version of Python, `print` was a keyword.
Now, `print` is a function; you need to use parentheses to call it.
(190) print is a function 6¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\print_non_paren_non_string1.py", line 1
print hello world!
^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
Did you mean `print(...)`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\print_non_paren_non_string1.py'
at the location indicated.
1| print hello world!
^^^^^^^^^^^
Perhaps you need to type
print(...)
In older version of Python, `print` was a keyword.
Now, `print` is a function; you need to use parentheses to call it.
Note that arguments of `print` must be separated by commas.
(191) print is a function 7¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\print_non_paren_non_string2.py", line 1
print len("hello") hello
^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
Did you mean `print(...)`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\print_non_paren_non_string2.py'
at the location indicated.
1| print len("hello") hello
^^^^^^^^^^^^^^^^^^
Perhaps you need to type
print(...)
In older version of Python, `print` was a keyword.
Now, `print` is a function; you need to use parentheses to call it.
Note that arguments of `print` must be separated by commas.
(192) Calling python from interpreter¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\python_interpreter.py", line 1
python -i friendly
^^^^^^^^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\python_interpreter.py'
at the location indicated.
1| python -i friendly
^^^^^^^^
I am guessing that you are attempting to use Python to run a program.
You must do so from a terminal and not from a Python interpreter.
(193) problem with assigning a variable to Python¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\python_not_interpreter.py", line 1
python = a b
^
SyntaxError: invalid syntax
Did you forget something between `a` and `b`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\python_not_interpreter.py'
at the location indicated.
1| python = a b
^^^
Python indicates that the error is caused by `b` written immediately after `a`.
Perhaps you meant to insert an operator like `+; -; *; ,`
between `a` and `b`.
The following lines of code would not cause any `SyntaxError`:
python = a + b
python = a - b
python = a * b
python = a, b
Note: these are just some of the possible choices and that
some of them might raise other types of exceptions.
(194) Quote inside a string¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\quote_inside_string.py", line 3
message = 'I don't mind.'
^
SyntaxError: unterminated string literal (detected at line 3)
Perhaps you forgot to escape a quote character.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\quote_inside_string.py'
at the location indicated.
3| message = 'I don't mind.'
^
I suspect that you were trying to use a quote character inside a string
that was enclosed in quotes of the same kind.
Perhaps you should have escaped the inner quote character:
message = 'I don\'t mind.'
^^
(195) Raising multiple exceptions¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\raise_multiple_exceptions.py", line 2
raise X, Y
^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\raise_multiple_exceptions.py'
at the location indicated.
2| raise X, Y
^
It looks like you are trying to raise an exception using Python 2 syntax.
(196) Cannot use return outside function¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\return_outside_function.py", line 3
return
^^^^^^
SyntaxError: 'return' outside function
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\return_outside_function.py'
at the location indicated.
3| return
^^^^^^
You can only use a `return` statement inside a function or method.
(197) Missing exponent for scientific notation¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\scientific_notation_missing_exponent.py", line 1
a = 1.5e
^
SyntaxError: invalid decimal literal
Did you mean `1.5e0`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\scientific_notation_missing_exponent.py'
at the location indicated.
1| a = 1.5e
^^^^
Python tells us that you have written an invalid number.
However, I think that the problem might be the following.
Did you mean `1.5e0`?
Perhaps you meant to write `1.5e0` in scientific notation
and forgot the numerical value for the exponent.
(198) Semicolon instead of colon¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\semi_colon_instead_of_colon.py", line 1
if True; # A comment
^
SyntaxError: invalid syntax
Did you mean to write a colon?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\semi_colon_instead_of_colon.py'
at the location indicated.
1| if True; # A comment
^
You wrote a semicolon, `;`, where a colon was expected.
(199) Semicolon instead of comma - 1¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\semi_colon_instead_of_comma_1.py", line 1
a = [1, 2; 3]
^
SyntaxError: invalid syntax
Did you mean to write a comma?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\semi_colon_instead_of_comma_1.py'
at the location indicated.
1| a = [1, 2; 3]
^
You wrote a semicolon, `;`, where a comma was expected.
(200) Semicolon instead of commas - 2¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\semi_colon_instead_of_comma_2.py", line 1
a = [1; 2; 3]
^
SyntaxError: invalid syntax
Did you mean to write commas?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\semi_colon_instead_of_comma_2.py'
at the location indicated.
1| a = [1; 2; 3]
^
You wrote semicolons, `;`, where commas were expected.
(201) Semicolon instead of commas - 3¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\semi_colon_instead_of_comma_3.py", line 1
a = [1; 2; 3];
^
SyntaxError: invalid syntax
Did you mean to write commas?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\semi_colon_instead_of_comma_3.py'
at the location indicated.
1| a = [1; 2; 3];
^
You wrote semicolons, `;`, where commas were expected.
(202) Code block inside comprehension¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\should_be_comprehension.py", line 2
for i in 1, 2, 3:
^^^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\should_be_comprehension.py'
at the location indicated.
1| a = [
-->2| for i in 1, 2, 3:
^^^
3| i**2
4| ]
Perhaps you wrote a statement beginning a code block
intended to be part of a list comprehension.
You cannot have separate code blocks inside list comprehensions.
If this explanation is incorrect, please report this case.
(203) Single = instead of double == with if¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\single_equal_with_if.py", line 3
if i % 2 = 0:
^^^^^
SyntaxError: cannot assign to expression here. Maybe you meant '==' instead of '='?
Perhaps you needed `==` instead of `=`.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\single_equal_with_if.py'
at the location indicated.
3| if i % 2 = 0:
^^^^^
You wrote an expression that includes some mathematical operations
on the left-hand side of the equal sign which should be
only used to assign a value to a variable.
(204) Single = instead of double == with elif¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\single_equal_with_elif.py", line 5
elif i % 2 = 0:
^^^^^
SyntaxError: cannot assign to expression here. Maybe you meant '==' instead of '='?
Perhaps you needed `==` instead of `=`.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\single_equal_with_elif.py'
at the location indicated.
5| elif i % 2 = 0:
^^^^^
You wrote an expression that includes some mathematical operations
on the left-hand side of the equal sign which should be
only used to assign a value to a variable.
(205) Single = instead of double == with while¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\single_equal_with_while.py", line 4
while a = 1:
^^^^^
SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?
Perhaps you needed `==` or `:=` instead of `=`.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\single_equal_with_while.py'
at the location indicated.
4| while a = 1:
^^^^^
You used an assignment operator `=`; perhaps you meant to use
an equality operator, `==`, or the walrus operator `:=`.
(206) Space between operators 1¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\space_between_operators_1.py", line 1
a = 2 * * 5
^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\space_between_operators_1.py'
at the location indicated.
1| a = 2 * * 5
^ ^
You cannot have write the same operator, `*`, twice in a row.
Perhaps you wrote one of them by mistake
or forgot to write something between them.
Or perhaps you included a space by mistake between the two operators
and meant to write `**` as a single operator.
(207) Space between operators 2¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\space_between_operators_2.py", line 1
a / = b
^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\space_between_operators_2.py'
at the location indicated.
1| a / = b
^ ^
You cannot have these two operators, `/` and `=`,
following each other. Perhaps you wrote one of them by mistake
or forgot to write something between them.
Or perhaps you included a space by mistake between the two operators
and meant to write `/=` as a single operator.
(208) Space in variable name¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\space_in_variable_name.py", line 1
my name = André
^^^^
SyntaxError: invalid syntax
Did you mean `my_name`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\space_in_variable_name.py'
at the location indicated.
1| my name = André
^^^^
You cannot have spaces in identifiers (variable names).
Perhaps you meant `my_name`?
(209) Wrong target for star assignment¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\star_assignment_target.py", line 1
*a = 1
^^
SyntaxError: starred assignment target must be in a list or tuple
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\star_assignment_target.py'
at the location indicated.
1| *a = 1
^^
A star assignment must be of the form:
... *name = list_or_tuple
(210) Too many nested blocks¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\too_many_nested_blocks.py", line 22
while 22:
^-->
SyntaxError: too many statically nested blocks
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\too_many_nested_blocks.py'
at the location indicated.
22| while 22:
^^^^^
Your code is too complex for Python:
you need to reduce the number of indented code blocks
contained inside other code blocks.
(211) Too many nested parentheses.¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\too_many_parentheses.py", line 4
((((((((((((((((((((((((((((((((((
^
SyntaxError: too many nested parentheses
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\too_many_parentheses.py'
at the location indicated.
1| ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
2| ((((((((((((((((((((((((((((((((((((((((((((((((((((((((
3| (((((((((((((((((((((((((((((((((((((((((((((((((((
-->4| ((((((((((((((((((((((((((((((((((
^
5| ))))))))))))))))))))))))))))))))))))))))))))))))))
6| )))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
7| ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
Your code is too complex for Python:
you need to reduce the number of parentheses
contained inside other parentheses.
(212) Trailing comma in import statement¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\trailing_comma_in_import.py", line 2
from math import sin, cos,
^
SyntaxError: trailing comma not allowed without surrounding parentheses
Did you write a comma by mistake?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\trailing_comma_in_import.py'
at the location indicated.
2| from math import sin, cos,
^
Python indicates that you need to surround an expression
ending with a comma by parentheses.
However, if you remove the last comma, there will be no syntax error.
Perhaps you meant to write
`from math import sin, cos`
(213) Triple-equal sign¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\triple_equal.py", line 3
x = y === z
^
SyntaxError: invalid syntax
Did you mean to use `is` instead of `===`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\triple_equal.py'
at the location indicated.
3| x = y === z
^^^
You wrote three equal signs in a row which is allowed in some
programming languages, but not in Python. To check if two objects
are equal, use two equal signs, `==`; to see if two names represent
the exact same object, use the operator `is`.
(214) Unclosed bracket¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unclosed_bracket.py", line 5
return [1, 2, 3
^
SyntaxError: '[' was never closed
The square bracket `[` was never closed.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unclosed_bracket.py'
at the location indicated.
-->5| return [1, 2, 3
^
6|
7| print(foo())
8|
The opening square bracket `[` on line 5 is not closed.
5: return [1, 2, 3
^
(215) Unclosed parenthesis - 1¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unclosed_paren_1.py", line 2
x = int('1'
^
SyntaxError: '(' was never closed
The parenthesis `(` was never closed.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unclosed_paren_1.py'
at the location indicated.
-->2| x = int('1'
^
3| if x == 1:
4| print('yes')
5|
The opening parenthesis `(` on line 2 is not closed.
2: x = int('1'
^
(216) Unclosed parenthesis - 2¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unclosed_paren_2.py", line 2
a = (b+c
^
SyntaxError: '(' was never closed
The parenthesis `(` was never closed.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unclosed_paren_2.py'
at the location indicated.
-->2| a = (b+c
^
3| d = a*a
4|
The opening parenthesis `(` on line 2 is not closed.
2: a = (b+c
^
(217) Unclosed parenthesis - 3¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unclosed_paren_3.py", line 7
if 2:
^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unclosed_paren_3.py'
at the location indicated.
5| print(((123))
6|
-->7| if 2:
^
8| print(123))
The opening parenthesis `(` on line 5 is not closed.
5: print(((123))
^
If this is incorrect, please report this case.
(218) Unclosed parenthesis - 4¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unclosed_paren_4.py", line 4
def test():
^^^
SyntaxError: invalid syntax
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unclosed_paren_4.py'
at the location indicated.
2| print('hello'
3|
-->4| def test():
^^^
The opening parenthesis `(` on line 2 is not closed.
2: print('hello'
^
(219) Content passed continuation line character¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unexpected_after_continuation_character.py", line 5
print(\t)
^
SyntaxError: unexpected character after line continuation character
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unexpected_after_continuation_character.py'
at the location indicated.
5| print(\t)
^
You are using the continuation character `\` outside of a string,
and it is followed by some other character(s).
I am guessing that you forgot to enclose some content in a string.
(220) Unexpected EOF while parsing¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unexpected_eof.py", line 5
return [1, 2, 3,
^
SyntaxError: '[' was never closed
The square bracket `[` was never closed.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unexpected_eof.py'
at the location indicated.
-->5| return [1, 2, 3,
^
6|
7| print(foo())
8|
The opening square bracket `[` on line 5 is not closed.
5: return [1, 2, 3,
^
(221) Invalid character (unicode fraction 3/4)¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unicode_fraction.py", line 1
a = ¾ # 3/4
^
SyntaxError: invalid character '¾' (U+00BE)
Did you mean `3/4`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unicode_fraction.py'
at the location indicated.
1| a = ¾ # 3/4
^
Did you use copy-paste?
Python indicates that you used the unicode character `¾`
which is not allowed.
You used the unicode character ¾ which is known as
VULGAR FRACTION THREE QUARTERS
I suspect that you meant to write the fraction `3/4` instead.
(222) Invalid character (unicode fraction 1/2)¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unicode_fraction2.py", line 1
a = 1½ # 1 1/2
^
SyntaxError: invalid decimal literal
Did you mean `1/2`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unicode_fraction2.py'
at the location indicated.
1| a = 1½ # 1 1/2
^^
Python tells us that you have written an invalid number.
However, I think that the problem might be the following.
You used the unicode character ½ which is known as
VULGAR FRACTION ONE HALF
I suspect that you meant to write the fraction `1/2` instead.
(223) Invalid character (unicode fraction slash)¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unicode_fraction3.py", line 1
a = 22 ⁄ 7
^
SyntaxError: invalid character '⁄' (U+2044)
Did you mean to use the division operator, `/`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unicode_fraction3.py'
at the location indicated.
1| a = 22 ⁄ 7
^
Did you use copy-paste?
Python indicates that you used the unicode character `⁄`
which is not allowed.
I suspect that you used the unicode character known as
'FRACTION SLASH', which looks similar to
but is different from the division operator `/`.
(224) Invalid character (unicode quote)¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unicode_quote.py", line 3
a = « hello »
^
SyntaxError: invalid character '«' (U+00AB)
Did you mean to use a normal quote character, `'` or `"`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unicode_quote.py'
at the location indicated.
3| a = « hello »
^
Did you use copy-paste?
Python indicates that you used the unicode character `«`
which is not allowed.
I suspect that you used a fancy unicode quotation mark
whose name is LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
instead of a normal single or double quote for a string.
(225) Invalid character (unicode quote2)¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unicode_quote2.py", line 2
a = ‹ hello ›
^
SyntaxError: invalid character '‹' (U+2039)
Did you mean to use a normal quote character, `'` or `"`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unicode_quote2.py'
at the location indicated.
2| a = ‹ hello ›
^
Did you use copy-paste?
Python indicates that you used the unicode character `‹`
which is not allowed.
I suspect that you used a fancy unicode quotation mark
whose name is SINGLE LEFT-POINTING ANGLE QUOTATION MARK
instead of a normal single or double quote for a string.
(226) Invalid character (mistaken <)¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unicode_quote3.py", line 2
if a ‹ hello:
^
SyntaxError: invalid character '‹' (U+2039)
Did you mean to use a normal quote character, `'` or `"`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unicode_quote3.py'
at the location indicated.
2| if a ‹ hello:
^
Did you use copy-paste?
Python indicates that you used the unicode character `‹`
which is not allowed.
I suspect that you used a fancy unicode quotation mark
whose name is SINGLE LEFT-POINTING ANGLE QUOTATION MARK
instead of a normal single or double quote for a string.
Or perhaps, you meant to write a less than sign, `<`.
(227) Invalid character (mistaken >)¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unicode_quote4.py", line 2
if a › hello:
^
SyntaxError: invalid character '›' (U+203A)
Did you mean to use a normal quote character, `'` or `"`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unicode_quote4.py'
at the location indicated.
2| if a › hello:
^
Did you use copy-paste?
Python indicates that you used the unicode character `›`
which is not allowed.
I suspect that you used a fancy unicode quotation mark
whose name is SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
instead of a normal single or double quote for a string.
Or perhaps, you meant to write a greater than sign, `>`.
(228) Invalid character (mistaken comma)¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unicode_quote5.py", line 2
a = (1‚ 2)
^
SyntaxError: invalid decimal literal
Did you mean to write a comma?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unicode_quote5.py'
at the location indicated.
2| a = (1‚ 2)
^^
Python tells us that you have written an invalid number.
However, I think that the problem might be the following.
I suspect that you used a fancy unicode quotation mark
whose name is SINGLE LOW-9 QUOTATION MARK.
Perhaps, you meant to write a comma.
(229) Unmatched closing curly bracket¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unmatched_closing_curly.py", line 6
3, 4,}}
^
SyntaxError: unmatched '}'
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unmatched_closing_curly.py'
at the location indicated.
4| a = {1,
5| 2,
-->6| 3, 4,}}
^
The closing curly bracket `}` on line 6 does not match anything.
(230) Unmatched closing parenthesis¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unmatched_closing_paren.py", line 6
3, 4,))
^
SyntaxError: unmatched ')'
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unmatched_closing_paren.py'
at the location indicated.
4| a = (1,
5| 2,
-->6| 3, 4,))
^
The closing parenthesis `)` on line 6 does not match anything.
(231) Mismatched brackets - 1¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unmatched_closing_bracket_1.py", line 2
x = (1, 2, 3]
^
SyntaxError: closing parenthesis ']' does not match opening parenthesis '('
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unmatched_closing_bracket_1.py'
at the location indicated.
2| x = (1, 2, 3]
^ ^
The closing square bracket `]` on line 2 does not match the opening parenthesis `(` on line 2.
2: x = (1, 2, 3]
^ ^
(232) Mismatched brackets - 2¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unmatched_closing_bracket_2.py", line 4
3]
^
SyntaxError: closing parenthesis ']' does not match opening parenthesis '(' on line 2
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unmatched_closing_bracket_2.py'
at the location indicated.
-->2| x = (1,
^
3| 2,
-->4| 3]
^
The closing square bracket `]` on line 4 does not match the opening parenthesis `(` on line 2.
2: x = (1,
^
4: 3]
^
(233) Unmatched brackets - 3¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unmatched_closing_bracket_3.py", line 3
3]]
^
SyntaxError: unmatched ']'
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unmatched_closing_bracket_3.py'
at the location indicated.
1| x = [1,
2| 2,
-->3| 3]]
^
The closing square bracket `]` on line 3 does not match anything.
(234) Unpacking a dict value¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unpacking_dict_value.py", line 1
{'a': *(1, 2, 3)}
^^^^^^^^^^
SyntaxError: cannot use a starred expression in a dictionary value
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unpacking_dict_value.py'
at the location indicated.
1| {'a': *(1, 2, 3)}
^^^^^^^^^^
It looks like you tried to use a starred expression as a dict value;
this is not allowed.
The following statement has no syntax error:
{'a': (1, 2, 3)}
(235) Unterminated triple quoted string¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unterminated_triple_quote_string.py", line 1
some_text = """In a land
^
SyntaxError: unterminated triple-quoted string literal (detected at line 4)
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unterminated_triple_quote_string.py'
at the location indicated.
1| some_text = """In a land
^^^^^^^^^^^^
You started writing a triple-quoted string but never wrote
the triple quotes needed to end the string.
(236) TabError¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\tab_error.py", line 7
pass
^
TabError: inconsistent use of tabs and spaces in indentation
A `TabError` indicates that you have used both spaces
and tab characters to indent your code.
This is not allowed in Python.
Indenting your code means to have block of codes aligned vertically
by inserting either spaces or tab characters at the beginning of lines.
Python's recommendation is to always use spaces to indent your code.
Python could not understand the code in the file
'TESTS:\syntax\tab_error.py'
at the location indicated.
7| pass
^^^^
(237) Wrong word instead of expect¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\typo_in_except.py", line 3
something Exception:
^^^^^^^^^
SyntaxError: expected 'except' or 'finally' block
Did you mean `except Exception:`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\typo_in_except.py'
at the location indicated.
3| something Exception:
^^^^^^^^^
You wrote a `try` block which did not include an `except` nor a `finally` block.
Perhaps you meant to write
except Exception:
(238) Typo in finally¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\typo_in_finally.py", line 3
finnally:
^^^^^^^^
SyntaxError: expected 'except' or 'finally' block
Did you mean `finally:`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\typo_in_finally.py'
at the location indicated.
3| finnally:
^^^^^^^^
You wrote a `try` block which did not include an `except` nor a `finally` block.
Perhaps you meant to write
finally:
(239) EOL unescaped backslash¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unescaped_backslash.py", line 1
a = "abc\"
^
SyntaxError: unterminated string literal (detected at line 1)
Did you forget to escape a backslash character?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unescaped_backslash.py'
at the location indicated.
1| a = "abc\"
^
You started writing a string with a single or double quote
but never ended the string with another quote on that line.
Perhaps you meant to write the backslash character, `\`
as the last character in the string and forgot that you
needed to escape it by writing two `\` in a row.
(240) Using the backquote character¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\use_backquote.py", line 3
a = `1`
^
SyntaxError: invalid syntax
You should not use the backquote character.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\use_backquote.py'
at the location indicated.
3| a = `1`
^
You are using the backquote character.
Either you meant to write a single quote, ', or copied Python 2 code;
in this latter case, use the function `repr(x)`.
(241) unicode error¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\unicode_error.py", line 1
path = "c:\Users\andre"
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
Perhaps you need to double the backslash characters.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\unicode_error.py'
at the location indicated.
1| path = "c:\Users\andre"
^^^^^^^^^^^^^^^^
I suspect that you wrote a string that contains
one backslash character, `\` followed by an uppercase `U`
and some more characters.
Python likely interpreted this as indicating the beginning of
what is known as an escape sequence for special unicode characters.
To solve the problem, either write a so-called 'raw string'
by adding the letter `r` as a prefix in
front of the string, or replace `\U`, by `\\U`.
(242) Walrus instead of equal¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\walrus_instead_of_equal.py", line 1
a := 3
^^
SyntaxError: invalid syntax
Did you mean to use `=`?
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\walrus_instead_of_equal.py'
at the location indicated.
1| a := 3
^^
You use the augmented assignment operator `:=` where
the normal assignment operator `=` was required.
(243) Missing condition in while statement¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\while_missing_condition.py", line 1
while:
^
SyntaxError: invalid syntax
You forgot to add a condition.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\while_missing_condition.py'
at the location indicated.
1| while:
^
A `while` loop requires a condition:
while condition:
...
(244) Would-be variable declaration¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\would_be_type_declaration_1.py", line 3
if var start := begin < end:
^^^^^
SyntaxError: invalid syntax
You do not need to declare variables in Python.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\would_be_type_declaration_1.py'
at the location indicated.
3| if var start := begin < end:
^^^^^
It looks like you were trying to declare that `start` was
a variable using the word `var`.
If you remove `var`, you will have a valid Python statement.
(245) Would-be variable declaration - 2¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\would_be_type_declaration_2.py", line 5
var start := begin < end
^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
You do not need to declare variables in Python.
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\would_be_type_declaration_2.py'
at the location indicated.
4| if (
-->5| var start := begin < end
^^^^^^^^^
6| ):
It looks like you were trying to declare that `var` was
a variable using the word `var`.
If you remove `var`, you will have a valid Python statement.
(246) Cannot use yield outside function¶
Traceback (most recent call last):
File "TESTS:\trb_syntax_common.py", line 52, in create_tracebacks
__import__(name)
File "TESTS:\syntax\yield_outside_function.py", line 1
(yield i) == 3
^^^^^^^
SyntaxError: 'yield' outside function
A `SyntaxError` occurs when Python cannot understand your code.
Python could not understand the code in the file
'TESTS:\syntax\yield_outside_function.py'
at the location indicated.
1| (yield i) == 3
^^^^^
You can only use a `yield` statement inside a function.