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

False positive E1136: Value 'typing.ChainMap' is unsubscriptable (unsubscriptable-object) #2849

Closed
jhbuhrman opened this issue Apr 2, 2019 · 3 comments
Labels
Bug 🪲 Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) typing

Comments

@jhbuhrman
Copy link

Steps to reproduce

  1. Create the following file named pylint_chainmap.py:
import typing
from collections import ChainMap


def check_pylint_chain_map() -> typing.ChainMap[str, typing.Any]:
    return ChainMap({"answer": 42})
  1. pylint --reports=n --score=n --disable=C0111 pylint_chainmap.py

Please note that mypy is perfectly happy with this source file.

Current behavior

************* Module pylint_chainmap
pylint_chainmap.py:5:32: E1136: Value 'typing.ChainMap' is unsubscriptable (unsubscriptable-object)

Expected behavior

pylint --version output

pylint 2.3.1
astroid 2.2.5
Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)]
@jhbuhrman
Copy link
Author

jhbuhrman commented Apr 2, 2019

Might it have something to do with the conditional definition in typing.py:2036? ...

if hasattr(collections, 'ChainMap'):
    # ChainMap only exists in 3.3+
    __all__.append('ChainMap')

    class ChainMap(collections.ChainMap, MutableMapping[KT, VT],
                   extra=collections.ChainMap):

    ...

@PCManticore
Copy link
Contributor

@jhbuhrman It's entirely possible that the inference is tripped by the conditional definition. We need to add support for some typing constructs in astroid, the library that pylint uses for type inference.

@cdce8p
Copy link
Member

cdce8p commented Oct 17, 2021

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

@cdce8p cdce8p closed this as completed Oct 17, 2021
@cdce8p cdce8p added the typing label Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) typing
Projects
None yet
Development

No branches or pull requests

3 participants