pylint icon indicating copy to clipboard operation
pylint copied to clipboard

Incorrect 'unsubscriptable-object' reported

Open ei14 opened this issue 1 year ago • 1 comments

Steps to reproduce

Running pylint 3.1.0 to this code will warn about incorrect 'unsubscriptable-object':

import numpy as np

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

Current behavior

Running pylint warns:

************* Module test
example.py:5:6: E1136: Value 'converted' is unsubscriptable (unsubscriptable-object)

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

Expected behavior

No warn

pylint --version output

pylint 3.1.0 astroid 3.1.0 Python 3.12.3 (main, Apr 23 2024, 09:16:07) [GCC 13.2.1 20240417]

Maybe related to: #3139 ?

ei14 avatar May 02 '24 16:05 ei14

I can confirm that and found a possible explanation:

Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.__version__
'1.26.4'
>>> x = numpy.int16(42)
>>> type(x)
<class 'numpy.int16'>
>>> y = numpy.int16([1,42])
>>> type(y)
<class 'numpy.ndarray'>

numpy.int16() used on an array will give you a numpy.ndarray instance instead.

UlrichEckhardt avatar May 03 '24 17:05 UlrichEckhardt