x.py with the following code:from typing import overload, Union
class C:
@overload
def get(self) -> str:
pass
@overload
def get(self, default: int) -> Union[str, int]:
pass
def get(self, default=None):
return '' if default is None else default
_ = C().get(1)
x.py with too-many-function-args enabledpylint --disable=all --enable=too-many-function-args --score=no x.py
pylint thinks C's get method can't take an argument:
************* Module x
x.py:17:4: E1121: Too many positional arguments for method call (too-many-function-args)
No error should be output. pylint should understand that a caller is permitted to match any of the overloads, not just the first one. (Note that pylint does the correct thing for module-level functions. This appears to be specific to class members.)
I reproduced with the dev version
pylint 2.1.1
astroid 2.1.0-dev
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170118]
and also the latest stable release
pylint 2.1.1
astroid 2.0.4
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170118]
Thanks for the report.
I think this is a general lack of @overload support, as shown when running PyLint on the following program:
from typing import overload
@overload
def double(item: int) -> int:
pass
@overload
def double(item: str) -> str:
pass
def double(item):
return item * 2
PyLint will report:
overload.py:4:11: W0613: Unused argument 'item' (unused-argument)
overload.py:7:0: E0102: function already defined line 4 (function-redefined)
overload.py:7:11: W0613: Unused argument 'item' (unused-argument)
overload.py:9:0: E0102: function already defined line 4 (function-redefined)
While all of the things PyLint reports are true, they are also normal when using @overload, so they shouldn't be considered warnings or errors.
Yes, we just need to fix this.
The original report is closed by https://github.com/PyCQA/pylint/commit/75ae5cc302b7c9b3b8b21d2f2e2b4fc0449eebbd while the @mthuurne issue is solved by https://github.com/PyCQA/pylint/commit/1669bc3868b198a1e97fae4fa60e0d6cfaed53d9. The first one is part of 2.5 which will be released in the following weeks.
Most helpful comment
Yes, we just need to fix this.