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

Enum: Value 'self.value' is unsubscriptable (unsubscriptable-object) where value is a tuple #2063

Closed
geckon opened this issue May 4, 2018 · 6 comments
Labels

Comments

@geckon
Copy link

geckon commented May 4, 2018

Steps to reproduce

#! python3

from enum import Enum

class MyEnum(Enum):
    FOO = (1, "f")
    BAR = (2, "b")

    def __str__(self):
        return self.value[1]

Run pylint on the file above.

Current behavior

E: 10,15: Value 'self.value' is unsubscriptable (unsubscriptable-object)

Expected behavior

No error - value here is a tuple (and can't be reassigned).

pylint --version output

$ pylint --version
No config file found, using default configuration
pylint 1.8.4, 
astroid 1.6.3
Python 3.4.6 (default, Mar 22 2017, 12:26:13) [GCC]
geckon added a commit to geckon/hockepy that referenced this issue May 4, 2018
Fix for #29 introduced two pylint "errors" which I believe are bugs in
pylint though. The latest pylint version 1.8.4 doesn't help though and
so I reported two issues to pylint:
pylint-dev/pylint#2062
pylint-dev/pylint#2063

Hockepy will probably have broken builds due to these false positive
pylint errors until those two issues are fixed.
@PCManticore
Copy link
Contributor

Thank you, I can reproduce the issue!
The source of problems for enum comes from our astroid brain tip for the enum library (https://github.com/PyCQA/astroid/blob/master/astroid/brain/brain_namedtuple_enum.py#L199), which is somewhat lossy in some areas as this one (if I recall correctly we don't fully reuse the values provided in the enum).

@bje-
Copy link

bje- commented Oct 10, 2019

I am also seeing this now after an upgrade. The message is:

test.py:5: [E1136(unsubscriptable-object), ] Value 'x.shape' is unsubscriptable

Test case:

"""Test case."""
import numpy as np

x = np.zeros(10, 10)
y = x.shape[0]

@hippo91
Copy link
Contributor

hippo91 commented Dec 1, 2019

@bje- in fact it is a totally different problem than the one reported by @geckon .
No need to open a new issue anyway, because it is the same as #3139.

@aakash77
Copy link

I was facing the same issue, after providing the type of the value it fixed my issue. So something like:

class MyEnum(Enum):
    value: Tuple[int, str]
    FOO = (1, "f")
    BAR = (2, "b")

    def __str__(self):
        return self.value[1]

@hippo91
Copy link
Contributor

hippo91 commented Dec 20, 2020

@aakash77 thanks for the hint!

mattgodbolt added a commit to compiler-explorer/infra that referenced this issue Feb 14, 2021
@mbyrnepr2
Copy link
Member

This no longer appears to be an issue on latest main:

pylint 2.14.0-dev0
astroid 2.11.4
Python 3.9.10 (v3.9.10:f2f3f53782, Jan 13 2022, 17:02:14) 
[Clang 6.0 (clang-600.0.57)]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants