[New-bugs-announce] [issue31241] ast col_offset wrong for list comprehensions, generators and tuples
Samuel Colvin
report at bugs.python.org
Sun Aug 20 15:03:54 EDT 2017
New submission from Samuel Colvin:
With Python 3.5 and 3.6 list comprehensions, generators and tuples have the col_offset for their ast nodes off by 1:
```
import ast
ast.parse('{a for a in range(3)}').body[0].value.col_offset
>> 0 # set comprehension correct
ast.parse('{a: 1 for a in range(3)}').body[0].value.col_offset
>> 0 # dict comprehension correct
ast.parse('[a for a in range(3)]').body[0].value.col_offset
>> 1 # list comprehension wrong!
ast.parse('(a for a in range(3))').body[0].value.col_offset
>> 1 # generator comprehension wrong!
ast.parse('[1, 2, 3]').body[0].value.col_offset
>> 0 # list correct
ast.parse('{1, 2, 3}').body[0].value.col_offset
>> 0 # set correct
ast.parse('{1: 1, 2: 2, 3: 3}').body[0].value.col_offset
>> 0 # dict correct
ast.parse('(1, 2, 3)').body[0].value.col_offset
>> 1 # tuple wrong!
```
I haven't tried 3.4, the issue could be there too.
There are some other related issues #16806 and #21295 but they don't seem quite the same.
----------
components: Interpreter Core
messages: 300606
nosy: samuelcolvin
priority: normal
severity: normal
status: open
title: ast col_offset wrong for list comprehensions, generators and tuples
versions: Python 3.5, Python 3.6
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue31241>
_______________________________________
More information about the New-bugs-announce
mailing list