[issue38166] ast identifies incorrect column for compound attribute lookups

Serhiy Storchaka report at bugs.python.org
Sun Sep 15 04:36:39 EDT 2019


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

AST for expression a.b.c is

         Attribute(
            value=Attribute(
               value=Name(
                  id='a',
                  ctx=Load(),
                  lineno=1,
                  col_offset=0,
                  end_lineno=1,
                  end_col_offset=1),
               attr='b',
               ctx=Load(),
               lineno=1,
               col_offset=0,
               end_lineno=1,
               end_col_offset=3),
            attr='c',
            ctx=Load(),
            lineno=1,
            col_offset=0,
            end_lineno=1,
            end_col_offset=5)

It contains one Name node for "a" and two Attribute nodes for "a.b" and "a.b.c". Every node has attributes lineno, col_offset, end_lineno and end_col_offset. Note that there are no nodes for "b" and "c", therefore there is no information about the location of "c" in AST.

----------
nosy: +serhiy.storchaka

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


More information about the Python-bugs-list mailing list