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 "Value '<val>' is unsubscriptable" with class method type overloading #9474

Closed
awarrier99 opened this issue Feb 29, 2024 · 2 comments
Labels
Duplicate 🐫 Duplicate of an already existing issue

Comments

@awarrier99
Copy link

awarrier99 commented Feb 29, 2024

Bug description

from typing import Literal, overload


class Test:
    __config: dict[str, list[int] | list[str] | list[float]]

    def __init__(self):
        self.__config = {"a": [0, 1], "b": ["abc", "def"], "c": [1.1, 2.2]}

    @overload
    def func(self, s: Literal["a"]) -> list[int]: ...
    @overload
    def func(self, s: Literal["b"]) -> list[str]: ...
    @overload
    def func(self, s: Literal["c"]) -> list[float]: ...
    def func(self, s: Literal["a"] | Literal["b"] | Literal["c"]) -> list[int] | list[str] | list[float]:
        return self.__config[s]


test = Test()
# pylint: disable=invalid-name
lst = test.func("c")
num = lst[0]

Configuration

No response

Command used

pylint test.py

Pylint output

************* Module test
test.py:40:6: E1136: Value 'lst' is unsubscriptable (unsubscriptable-object)

Expected behavior

I would expect to be able to index the returned list with no linting error. It's worth noting that this same example works when the functions are defined at the module level, it seems to be only an issue within a class.

Pylint version

pylint 3.0.3
astroid 3.0.3
Python 3.11.5 (main, Aug 24 2023, 15:18:16) [Clang 14.0.3 (clang-1403.0.22.14.1)]

OS / Environment

macOS Sonoma 14.1.1

Additional dependencies

No response

@awarrier99 awarrier99 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Feb 29, 2024
@jacobtylerwalls
Copy link
Member

Thanks for the report. '@overload' is not yet supported. Will close as a duplicate of pylint-dev/astroid#1015 / #5712

@jacobtylerwalls jacobtylerwalls added Duplicate 🐫 Duplicate of an already existing issue and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Mar 1, 2024
@jacobtylerwalls jacobtylerwalls closed this as not planned Won't fix, can't repro, duplicate, stale Mar 1, 2024
@awarrier99
Copy link
Author

@jacobtylerwalls ah sorry I obviously didn't search through the existing issues well enough. Thanks for the context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate 🐫 Duplicate of an already existing issue
Projects
None yet
Development

No branches or pull requests

2 participants