This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Justin McCann
Recipients Justin McCann
Date 2019-09-13.21:48:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1568411334.98.0.109884794691.issue38166@roundup.psfhosted.org>
In-reply-to
Content
This issue is related to https://github.com/microsoft/vscode-python/issues/7327 and https://github.com/PyCQA/pylint/issues/3103

For compound attribute access in variable references like a.b.c.d, the AST reports the column of the first variable/attribute in the sequence instead of the specific attribute location. For example, the location of  c is reported as column 0 (a) and not column 4 (c).

Here's the AST test case provided by a pylint developer in a comment on pylint issue 3103; I confirmed the behavior is the same in python 3.8.0b4.
```
$ python3.8
Python 3.8.0b4 (v3.8.0b4:d93605de72, Aug 29 2019, 21:47:47)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ast
>>> body = ast.parse('''
... print(x.item.akey > 2)
... ''')
>>> # x.item
... x_item = body.body[0].value.args[0].left.value
>>> print(x_item, x_item.attr, x_item.col_offset)
<_ast.Attribute object at 0x10a7751f0> item 6
>>> # x.item.akey
... print(x_item.value, x_item.value.col_offset) .  ### probably should be 8
<_ast.Name object at 0x10a775280> 6
```

Related issues:
* https://bugs.python.org/issue1440601 Add col information to parse & ast nodes
* https://bugs.python.org/issue10769 ast: provide more useful range information


Here is the resulting confusion when you use this output in pylint (and then VSCode highlights only "x" since it's the variable that starts in column 0):

Original pylint/vscode testcase:
```
class TestMe:
    def __init__(self):
        self.item = {'akey': 42}
        self.again = self

x = TestMe()
### pylint error message here is
###    testme.py:11:6: E1101: Instance of 'dict' has no 'akey' member (no-member)
### The problem is with `x.item`, but pylint shows the column for `x`
print(x.item.akey > 2)

print(x.again.item.doesnotexist)
```

Current behavior
$ pylint testme.py  -rn -sn
************* Module testme
testme.py:10:6: E1101: Instance of 'dict' has no 'akey' member (no-member)
testme.py:12:6: E1101: Instance of 'dict' has no 'doesnotexist' member (no-member)

Expected behavior
$ pylint testme.py  -rn -sn
************* Module testme
testme.py:10:8: E1101: Instance of 'dict' has no 'akey' member (no-member)
testme.py:12:14: E1101: Instance of 'dict' has no 'doesnotexist' member (no-member)

$ pylint --version output
pylint 2.3.1
astroid 2.2.5
Python 3.7.4 (default, Jul 9 2019, 18:13:23)
[Clang 10.0.1 (clang-1001.0.46.4)]
History
Date User Action Args
2019-09-13 21:48:54Justin McCannsetrecipients: + Justin McCann
2019-09-13 21:48:54Justin McCannsetmessageid: <1568411334.98.0.109884794691.issue38166@roundup.psfhosted.org>
2019-09-13 21:48:54Justin McCannlinkissue38166 messages
2019-09-13 21:48:54Justin McCanncreate