[issue21295] Python 3.4 gives wrong col_offset for Call nodes returned from ast.parse
Radek Novacek added the comment: There is still problem with col_offset is some situations, for example col_offset of the ast.Attribute should be 4 but is 0 instead: >>> for x in ast.walk(ast.parse('foo.bar')): ... if hasattr(x, 'col_offset'): ... print("%s: %d" % (x, x.col_offset)) ... <_ast.Expr object at 0x7fcdc84722b0>: 0 <_ast.Attribute object at 0x7fcdc84723c8>: 0 <_ast.Name object at 0x7fcdc8472438>: 0 Is there any solution to this problem? It causes problems in python support in KDevelop (kdev-python). -- ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue21295> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21295] Python 3.4 gives wrong col_offset for Call nodes returned from ast.parse
Radek Novacek added the comment: Aivar, I have to admit that my knowledge of this is limited, but as I understand it, the attribute is "bar" in the "foo.bar" expression. I can get beginning of the assignment by >>> ast.parse('foo.bar').body[0].value.value.col_offset 0 But how can I get position of the 'bar'? My guess is this: >>> ast.parse('foo.bar').body[0].value.col_offset but it still returns 0. Why this two col_offsets returns the same value? How can I get the position of 'bar' in 'foo.bar'? -- ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue21295> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21295] Python 3.4 gives wrong col_offset for Call nodes returned from ast.parse
Radek Novacek added the comment: I've ran the tests from first and second comment using python 3.5.0 and it seems it produces correct results: >>> import ast >>> tree = ast.parse("sin(0.5)") >>> first_stmt = tree.body[0] >>> call = first_stmt.value >>> print("col_offset of call expression:", call.col_offset) col_offset of call expression: 0 >>> print("col_offset of func of the call:", call.func.col_offset) col_offset of func of the call: 0 >>> tree = ast.parse("(sin\n(0.5))") >>> first_stmt = tree.body[0] >>> call = first_stmt.value >>> print("col_offset of call expression:", call.col_offset) col_offset of call expression: 1 >>> print("col_offset of func of the call:", call.func.col_offset) col_offset of func of the call: 1 >>> print("lineno of call expression:", call.lineno) lineno of call expression: 1 >>> print("lineno of func of the call:", call.lineno) lineno of func of the call: 1 -- nosy: +rnovacek ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue21295> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com