Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect 'unsubscriptable-object' reported #9590

Open
ei14 opened this issue May 2, 2024 · 1 comment
Open

Incorrect 'unsubscriptable-object' reported #9590

ei14 opened this issue May 2, 2024 · 1 comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Lib specific 💅 This affect the code from a particular library Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@ei14
Copy link

ei14 commented May 2, 2024

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 ei14 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label May 2, 2024
@UlrichEckhardt
Copy link
Contributor

UlrichEckhardt commented May 3, 2024

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.

@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code Lib specific 💅 This affect the code from a particular library Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Lib specific 💅 This affect the code from a particular library Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

3 participants