[issue33520] ast.Tuple has wrong col_offset

2018-05-15 Thread Isaiah Peng

New submission from Isaiah Peng :

The `col_offset` of the ast.Tuple node is set to the column offset of the first 
element, shown in code:

>>> a = "{1,2,3}"
>>> b = ast.parse(a).body[0]
>>> 
>>>   
>>> b.value.col_offset
0
>>> a = "[1,2,3]"   
>>> 
>>>   
>>> b = ast.parse(a).body[0]
>>> 
>>>   
>>> b.value.col_offset  
>>> 
>>>   
0   

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

It's correct for dict, set, list, even empty tuple, Though this is not a 
serious bug, for other python implementations that uses the tests as language 
spec, this is annoying.

--
components: Library (Lib)
messages: 316665
nosy: isaiah
priority: normal
severity: normal
status: open
title: ast.Tuple has wrong col_offset
type: behavior
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33520] ast.Tuple has wrong col_offset

2018-05-15 Thread Łukasz Langa

Łukasz Langa  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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33520] ast.Tuple has wrong col_offset

2018-05-15 Thread Łukasz Langa

Łukasz Langa  added the comment:

For comparison, a tuple without parentheses:

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

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33520] ast.Tuple has wrong col_offset

2018-05-15 Thread Isaiah Peng

Isaiah Peng  added the comment:

Thanks for the reply, that's quite reasonable, especially take the generator 
expression case into consideration. However I found this is not consistent with 
empty tuple:

>>> a = "()"
>>> 
>>>   
>>> ast.parse(a).body[0].value.col_offset   
>>> 
>>>   
0

It's true that the parenthesis is required to construct a tuple, but if the 
parenthesis is served as the starting point of the tuple, then the col_offset 
should be the opening parenthesis. i.e. in the following example, both should 
start from col 2:

  >>> 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

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33520] ast.Tuple has wrong col_offset

2018-05-15 Thread Isaiah Peng

Isaiah Peng  added the comment:

> It's true that the parenthesis is required to construct a tuple

Sorry, I mean the parenthesis is *not* required.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33520] ast.Tuple has wrong col_offset

2018-05-15 Thread R. David Murray

R. David Murray  added the comment:

No, the parenthesis are never part of the tuple itself, even if you can't write 
syntactically correct code without them. They just syntactically group the 
expression list to isolate it from the surrounding context.  It's the same 
principle as having an expression like (123).  That's an integer that happens 
to be surrounded by parenthesis.  The integer itself still starts at column 1.

--
nosy: +r.david.murray

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33520] ast.Tuple has wrong col_offset

2018-05-15 Thread R. David Murray

Change by R. David Murray :


--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33520] ast.Tuple has wrong col_offset

2018-05-15 Thread R. David Murray

R. David Murray  added the comment:

Oh, and the empty tuple is a specific syntactic construct that really is the 
empty parenthesis, so that's consistent with the language definition.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33520] ast.Tuple has wrong col_offset

2018-05-16 Thread Isaiah Peng

Isaiah Peng  added the comment:

Fair enough, thanks for clarification.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com