Pylint: Incorrect 'unsubscriptable-object' reported

Created on 25 Sep 2019  路  11Comments  路  Source: PyCQA/pylint

Steps to reproduce

Running pylint 2.4.1 to this code will want about incorrect 'unsubscriptable-object':

import numpy as np

arr = np.array([1, 2, 3])
shape = arr.shape
print(shape[0])

Current behavior

Running pylint warns:

...
example.py:5:6: E1136: Value 'shape' is unsubscriptable (unsubscriptable-object)

Expected behavior

No warn

pylint --version output

pylint 2.4.1
astroid 2.3.0
Python 3.7.2 (default, Dec 29 2018, 00:00:04)
[Clang 4.0.1 (tags/RELEASE_401/final)]

Maybe related to: #3129 ?

astroid bug

Most helpful comment

Thank you for reporting the issue, I can reproduce it as well.

All 11 comments

Downgrading to pylint<2.4 and astroid<2.3 appears to resolve this. Notably, downgrading only pylint does not help.

x-ref: https://gitlab.tiker.net/inducer/pytential/merge_requests/182

Thank you for reporting the issue, I can reproduce it as well.

@atilag, the PR PyCQA/astroid#732 should fix this issue.

I am using pylint 2.4.4. It still shows the error.

This should be fixed with the release of astroid==2.4.0.

Astroid 2.4.1 and pylint 2.5.2

My error raise from pymongo db e.g db[collection_name].insert_one(...)

I can reproduce the original issue as well. I don't believe this issue has been fixed or it momentarily was and the issue resurfaced with newer versions.

pylint 2.6.0
astroid 2.4.2
Python 3.8.6

@acxz thanks for your report. However i can not reproduce the original issue. For example linting the following code:

import numpy as np

arr = np.array([1, 2, 3])
shape = arr.shape
print(shape[0])

gives:

************* Module bug_pylint_3139
bug_pylint_3139.py:1:0: C0114: Missing module docstring (missing-module-docstring)

------------------------------------------------------------------
Your code has been rated at 7.50/10 (previous run: 7.50/10, +0.00)

with:

pylint 2.6.0
astroid 2.4.3
Python 3.8.2 (default, Sep 28 2020, 21:24:28) 
[GCC 8.3.

Thanks for looking into this, @hippo91! I cannot reproduce the issue with the original script either.
The following script, however, does give me the unsubscriptable-object

"""."""
import numpy as np

x_vec_list = [None] * 2
x_vec_list[0] = np.zeros(2)
x_vec_list[1] = np.zeros(2)

x1_vec = [x_vec[0] for x_vec in x_vec_list]

print(x1_vec)

gives:

************* Module test
test.py:8:10: E1136: Value 'x_vec' is unsubscriptable (unsubscriptable-object)

-----------------------------------
Your code has been rated at 1.67/10

with

pylint 2.6.0
astroid 2.4.2
Python 3.8.6 (default, Sep 30 2020, 04:00:38) 
[GCC 10.2.0]

Should I instead make a new issue for this snippet?

We can just track this over at #3637
sorry for kinda necro-bumping this issue, was the first one I found :stuck_out_tongue_winking_eye:

@acxz yes please open a different issue. In fact #3637 is probably not related to your issue but linked to panda support in astroid and pylint.

Sounds good, I deleted my comment on #3637 and opened a new issue at #3956

Was this page helpful?
0 / 5 - 0 ratings