-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
C: arguments-differIssues related to 'arguments-differ' and 'signature-differs' checksIssues related to 'arguments-differ' and 'signature-differs' checksFalse Positive 🦟A message is emitted but nothing is wrong with the codeA message is emitted but nothing is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationThis issue is accepted, sufficiently specified and now needs an implementation
Description
Bug description
Noticed that one while working on pylint-dev/astroid#1217 with @DanielNoord.
The logic for signature-differs
/ arguments-differ
can't handle function redefinitions as its common with typing.overload
. In particular I narrowed it down to two issue:
- All function definitions seem to be check, even those decorated with
overload
. - The point of comparison is always the first definition, even if that isn't the true signature.
--
The examples require Python 3.8 (due to the use of typing.Literal
). Not that they aren'T necessarily typed correctly. Just for illustration proposes.
Example 1
# pylint: disable=unused-argument,no-self-use,missing-docstring
from typing import Literal, Union, overload
class Parent:
@overload
def statement(self) -> int:
...
@overload
def statement(self, future: Literal[True]) -> str:
...
def statement(self, future: Literal[None, True] = None) -> Union[int, str]:
pass
class Child(Parent):
# Signature comparison happens with first definition - the overload
# Should use the actual function instead!
def statement(self, future=None): # arguments-differ (false-positive)
pass
Example 2
# pylint: disable=unused-argument,no-self-use,missing-docstring
from typing import Literal, Union, overload
class Parent2:
def statement(self, future: Literal[None, True] = None) -> Union[int, str]:
pass
class Child2(Parent2):
@overload
def statement(self, future: Literal[None] = ...) -> int:
...
@overload
def statement(self, future: Literal[True]) -> str: # signature-differs (false-positive)
# Even overloads are checked although these aren't required
# to have the correct signature
...
def statement(self, future: Literal[None, True] = None) -> Union[int, str]:
pass
Configuration
No response
Command used
pylint test.py
Pylint output
W0221: Number of parameters was 1 in 'Parent.statement' and is now 2 in overridden 'Child.statement' method (arguments-differ)
W0222: Signature differs from overridden 'statement' method (signature-differs)
Expected behavior
no errors
Pylint version
2.11.2-dev0
OS / Environment
No response
Additional dependencies
No response
Pierre-Sassoulas, frederikaalund and SubaruAraiDanielNoord
Metadata
Metadata
Assignees
Labels
C: arguments-differIssues related to 'arguments-differ' and 'signature-differs' checksIssues related to 'arguments-differ' and 'signature-differs' checksFalse Positive 🦟A message is emitted but nothing is wrong with the codeA message is emitted but nothing is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationThis issue is accepted, sufficiently specified and now needs an implementation