[issue33520] ast.Tuple has wrong col_offset

Łukasz Langa report at bugs.python.org
Tue May 15 13:33:18 EDT 2018


Łukasz Langa <lukasz at langa.pl> added the comment:

This is because technically parentheses aren't part of the tuple.  They are just organizational and unnecessary for the tuple to be recognized by the parser.

Those two are equivalent:

  >>> ast.parse("(1,2,3)").body[0].value.col_offset
  1
  >>> ast.parse("(1)").body[0].value.col_offset
  1

You can see similar behavior within generator expressions in contexts where the parentheses are not semantically required:

  >>> ast.parse("c(i for i in range(10))").body[0].value.args[0].col_offset
  2
  >>> ast.parse("c((i for i in range(10)))").body[0].value.args[0].col_offset
  3

----------
nosy: +lukasz.langa

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33520>
_______________________________________


More information about the Python-bugs-list mailing list