-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 - an overloaded method is reported to be unsubscriptable #5189
Comments
related pylint issues: pylint-dev/pylint#5189 pylint-dev/pylint#2778
related pylint issues: unsubscriptable-object: pylint-dev/pylint#5189 no-value-for-parameter: pylint-dev/pylint#2778
related pylint issues: unsubscriptable-object: pylint-dev/pylint#5189 no-value-for-parameter: pylint-dev/pylint#2778 PR Closed: Graviti-AI#1059
related pylint issues: unsubscriptable-object: pylint-dev/pylint#5189 no-value-for-parameter: pylint-dev/pylint#2778 PR Closed: #1059
My thanks to @AChenQ for reporting this issue. I've tried to minimize the repro case just a little further, and try to give some idea of the root cause. Consider the following code: '''docstring
'''
from __future__ import annotations
from typing import (
MutableMapping,
overload,
TypeVar,
)
Tk = TypeVar('Tk') # used for keys
Tv = TypeVar('Tv') # used for values
# pylint: disable-next=too-few-public-methods
class ProxyBuilder:
'''docstring
'''
# (in the following block, ignore[misc] disables "signatures
# overload with incompatible return types":)
@overload
def wrap( # type: ignore[misc]
self, value: MutableMapping[Tk, Tv]
) -> MutableMapping[Tk, Tv]: ...
@overload
def wrap(self, value: Tv) -> Tv: ...
def wrap(self, value: Tv) -> Tv:
'''docstring
Args:
value: ...
Returns:
...
'''
_ = self
return value
def test_function() -> None:
'''docstring
'''
proxy = ProxyBuilder().wrap({})
proxy[1] = 'one' What's (not) necessary for the issue to occur:
Asteroid seems to be to blameAsteroid appears to infer the return type of if supported_protocol and not supported_protocol(inferred, node):
self.add_message(msg, args=node.value.as_string(), node=node.value) ...the value of Workarounds not idealThis issue is particularly challenging to work around because it causes error to occur at every use of the return value, potentially raising dozens of errors for each call to Python and pylint versionsLatest (pip) versions of pylint/asteroid are affected on Python 3.8 and 3.9.
|
In case it helps, this simple example reproduces the issue too: from typing import Union, List, overload
class SomeClass:
@overload
def some_method(self, a: int) -> int:
...
@overload
def some_method(self, a: str) -> List[int]:
...
def some_method(self, a: Union[int, str]):
if isinstance(a, int):
return a
elif isinstance(a, str):
return [0, 0]
else:
raise ValueError(a)
SomeClass().some_method("bar")[0]
|
Partner to pylint-dev/astroid#1015 |
In fact, we are now closing |
Bug description
Pylint output
Expected behavior
No pylint error report.
Pylint version
OS / Environment
Mac OS
The text was updated successfully, but these errors were encountered: