Description
Bug report
Bug description:
I found the following while working on pysource-codegen, which generates random python code. I don't know any real world python code which does this.
echo "del (a,[b])" | python3.12 -m dis
0 0 RESUME 0
1 2 DELETE_NAME 0 (a)
4 DELETE_NAME 1 (b)
6 RETURN_CONST 0 (None)
echo "del (a,[b])" | python3.12 -m ast
Module(
body=[
Delete(
targets=[
Tuple(
elts=[
Name(id='a', ctx=Del()),
List(
elts=[
Name(id='b', ctx=Del())],
ctx=Del())],
ctx=Del())])],
type_ignores=[])
I think that this is most likely an bug in the parser.
Another issue that I found while working on this is that del (a,b)
and del a,b
generate different python ast.
echo "del (a,b)" | python3.12 -m ast
Module(
body=[
Delete(
targets=[
Tuple(
elts=[
Name(id='a', ctx=Del()),
Name(id='b', ctx=Del())],
ctx=Del())])],
type_ignores=[])
echo "del a,b" | python3.12 -m ast
Module(
body=[
Delete(
targets=[
Name(id='a', ctx=Del()),
Name(id='b', ctx=Del())])],
type_ignores=[])
The ast documentation says:
class ast.Delete(targets)
Represents a del statement. targets is a list of nodes, such as Name, Attribute or Subscript nodes
I don't know what the best solution to this problem should be, but I would like to have a correct documentation. Especially the case that ast.Tuple
could be a del target is missing and was confusing for me. I had expected that del (a,b)
and del a,b
would produce the same ast and that del (a,(b,c))
is invalid syntax.
del [a]
looks like a bug to me and I hope it can be fixed.
CPython versions tested on:
3.12
Operating systems tested on:
Linux