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

Regression: Value 'Collection' is unsubscriptable #2377

Closed
Spacerat opened this issue Aug 2, 2018 · 9 comments
Closed

Regression: Value 'Collection' is unsubscriptable #2377

Spacerat opened this issue Aug 2, 2018 · 9 comments
Labels
Bug 🪲 Hacktoberfest Help wanted 🙏 Outside help would be appreciated, good for new contributors High priority Issue with more than 10 reactions typing

Comments

@Spacerat
Copy link

Spacerat commented Aug 2, 2018

Steps to reproduce

Run pylint on this file

from typing import Collection

def myfunc(arg: Collection[int]):
    print(arg)

myfunc([1, 2, 3])

Current behavior

repro.py:3:16: E1136: Value 'Collection' is unsubscriptable (unsubscriptable-object)

Expected behavior

No errors.

pylint --version output

Breaks for 2.1.0:

pylint 2.1.0
astroid 2.0.2
Python 3.6.4 (default, Mar 12 2018, 17:50:21)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]

Does not break for 1.9.2:

pylint 1.9.2,
astroid 1.6.5
Python 3.6.4 (default, Mar 12 2018, 17:50:21)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]

If there is a configuration workaround for this (except for disabling unsubscriptable-object globally) that would be nice, but neither ignored-modules=typing or ignored-classes=Collection worked for me.

@Spacerat
Copy link
Author

Spacerat commented Aug 2, 2018

In fact, this seems to be a Python 3.6 specific issue.

pylint 2.1.0
astroid 2.0.2
Python 3.7.0 (default, Aug  1 2018, 18:01:40)
[Clang 9.0.0 (clang-900.0.39.2)]

There's no issue for 3.7, so I'm not sure if this should be considered a regression

@PCManticore
Copy link
Contributor

Hi, thanks for the report. I can also reproduce this bug.

@mthuurne
Copy link
Contributor

This issue also happens for me with the following versions:

pylint 2.2.2
astroid 2.0.4
Python 3.6.5 (default, Mar 31 2018, 19:45:04) [GCC]

@mplanchard
Copy link

Also seeing this with

pylint 2.3.1
astroid 2.2.5
Python 3.6.8 (default, Mar  5 2019, 06:26:06)

@mthuurne
Copy link
Contributor

mthuurne commented Oct 4, 2019

Looking at the code of typing.py, the way Collection is defined is very different between Python 3.6 and 3.7, so fixing this might not be trivial.

I think ignored-classes=Collection does not help as a workaround because PyLint doesn't consider Collection a class on Python 3.6: it reports Value 'Collection' is unsubscriptable after all.

I ended up using this workaround:

from typing import TYPE_CHECKING, Collection

if not TYPE_CHECKING:
    # Work around PyLint issue on Python 3.6.
    #   https://github.com/PyCQA/pylint/issues/2377
    from typing import Sequence # pylint: disable=ungrouped-imports
    Collection = Sequence # pylint: disable=invalid-name

@tuukkamustonen
Copy link

Also occurs on python 3.5:

pylint 2.4.4
astroid 2.3.1
Python 3.5.5 (default, May 29 2018, 10:15:24) 
[GCC 5.4.0 20160609]

@jnsnow
Copy link
Contributor

jnsnow commented Mar 31, 2020

I'm working on adding pylint (+mypy) to all of QEMU's CI for our test infrastructure. We use Python 3.6 as our minimum viable python version for test infrastructure, so we are encountering this issue.

It appears to be an issue on all 2.x.x pylint versions against Python 3.6.10.

For now, my workaround will likely be just using Sequence instead of Collection.

@remort
Copy link

remort commented Dec 16, 2020

Still hurts on

pylint 2.6.0
astroid 2.4.2
Python 3.6.8 (default, Jan 30 2019, 23:58:16) 

@Pierre-Sassoulas Pierre-Sassoulas added the High priority Issue with more than 10 reactions label May 30, 2021
@Pierre-Sassoulas Pierre-Sassoulas added the Help wanted 🙏 Outside help would be appreciated, good for new contributors label Jul 1, 2021
akaihola added a commit to akaihola/darker that referenced this issue Jul 30, 2021
akaihola added a commit to akaihola/darker that referenced this issue Jul 31, 2021
@cdce8p cdce8p added the typing label Oct 17, 2021
@cdce8p
Copy link
Member

cdce8p commented Oct 17, 2021

This issue seems to be fixed when testing with the latest pylint version. Closing it.
If you still encounter it, please report back and I'll be happy to reopen it.

@cdce8p cdce8p closed this as completed Oct 17, 2021
jemrobinson added a commit to jemrobinson/shui that referenced this issue Aug 18, 2022
bonzini pushed a commit to qemu/qemu that referenced this issue Feb 24, 2023
Pylint under 3.6 does not believe that Collection is subscriptable at
runtime. It is, making this a Pylint
bug. pylint-dev/pylint#2377

They closed it as fixed, but that doesn't seem to be true as of Pylint
2.13.9, the latest version you can install under Python 3.6. 2.13.9 was
released 2022-05-13, about seven months after the bug was closed.

The least-annoying fix here is to just use the concret type.

Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20230215000011.1725012-4-jsnow@redhat.com>
[Dumbed down from Sequence[str] to List[str], commit message adjusted]
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Hacktoberfest Help wanted 🙏 Outside help would be appreciated, good for new contributors High priority Issue with more than 10 reactions typing
Projects
None yet
Development

No branches or pull requests

9 participants