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

unsubscriptable-object error reported incorrectly #2416

Closed
pbasista opened this issue Aug 16, 2018 · 6 comments · Fixed by #2702
Closed

unsubscriptable-object error reported incorrectly #2416

pbasista opened this issue Aug 16, 2018 · 6 comments · Fixed by #2702
Labels

Comments

@pbasista
Copy link

Steps to reproduce

Run Pylint on the following code:

from typing import Generic, TypeVar

T = TypeVar("T")

class Test(Generic[T]):  # error is reported here
    pass

Current behavior

Pylint reports the following error:
E1136: Value 'Generic' is unsubscriptable (unsubscriptable-object)

Expected behavior

No error should be reported. Python documentation for Generic explicitly lists use cases where Generic is subscripted.

pylint --version output

$ pylint --version
pylint 2.1.1
astroid 2.0.4
Python 3.7.0 (default, Jun 27 2018, 14:40:03) 
[GCC 8.1.0]

This issue is not reproducible with Python 3.6. Might be related to issue #2377, which is only reproducible with Python 3.6.

pgavlin added a commit to pulumi/pulumi that referenced this issue Nov 9, 2018
Python 3.7 gets this rule wrong for `Generic[]`.

pylint-dev/pylint#2416 tracks this issue in pylint.
pgavlin added a commit to pulumi/pulumi that referenced this issue Nov 9, 2018
Python 3.7 gets this rule wrong for `Generic[]`.

pylint-dev/pylint#2416 tracks this issue in pylint.
mrshannon added a commit to ccarocean/yzal that referenced this issue Jan 3, 2019
Python 3.7 gets this rule wrong for `Generic[]`.

pylint-dev/pylint#2416 tracks this issue in pylint.
@pcorpet
Copy link
Contributor

pcorpet commented Jan 20, 2019

I believe this is due to Generic using __class_getitem__, see source code. And pylint does not handle __class_getitem__ yet.

PEP 560 introduced __class_getitem__.

pcorpet added a commit to pcorpet/pylint that referenced this issue Jan 20, 2019
pcorpet added a commit to pcorpet/pylint that referenced this issue Jan 20, 2019
pcorpet added a commit to pcorpet/pylint that referenced this issue Jan 20, 2019
PCManticore pushed a commit that referenced this issue Feb 4, 2019
Take into account `__class_getitem__` from PEP 560 and fixes some false
positives for `no-self-argument` and `unsubscriptable-object`

PEP: https://www.python.org/dev/peps/pep-0560/

Close #2416
@PCManticore
Copy link
Contributor

Thanks @pcorpet for the PR!

@idchlife
Copy link

Thanks for hard work at pylint!

Is it possible to use version with fix for Generic?

@vyshkant
Copy link

@PCManticore Could you please release this fix?

@PCManticore
Copy link
Contributor

@vyshkant I'll do a Pylint release today.

@belvedere-trading-user
Copy link

Thank you! I can verify that this fixed the issue on our end.

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

Successfully merging a pull request may close this issue.

6 participants