Skip to content

Commit f3b652d

Browse files
committed
Fix mypy errors
This commit fixes the ignoring of special methods on function overriding and also removes incorrect use of the attribute name.
1 parent 60dbe32 commit f3b652d

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

pylint/checkers/classes.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,12 @@ def _has_different_parameters(
283283
# check for the arguments' type
284284
original_type = original_param.parent.annotations[counter]
285285
if original_type is not None:
286-
original_type = str(original_param.parent.annotations[counter].name)
287-
288286
overridden_type = overridden_param.parent.annotations[counter]
289287
if overridden_type is not None:
290-
overridden_type = str(overridden_param.parent.annotations[counter].name)
291-
if original_type != overridden_type:
288+
if original_type.name != overridden_type.name:
292289
result.append(
293-
f"Parameter '{original_param.name}' was of type '{original_type}' and is now"
294-
+ f" of type '{overridden_type}' in"
290+
f"Parameter '{original_param.name}' was of type '{original_type.name}' and is now"
291+
+ f" of type '{overridden_type.name}' in"
295292
)
296293
counter += 1
297294

@@ -377,7 +374,7 @@ def _different_parameters(
377374
# unexpected-special-method-signature.
378375
# If the names are different, it doesn't matter, since they can't
379376
# be used as keyword arguments anyway.
380-
different_positional = different_kwonly = False
377+
output_messages.clear()
381378

382379
# Arguments will only violate LSP if there are variadics in the original
383380
# that are then removed from the overridden

tests/functional/a/arguments_differ.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ def __getitem__(self, key: int):
219219

220220
class OverridesSpecialMethod(HasSpecialMethod):
221221

222-
def __getitem__(self, cheie: int): #[arguments-differ]
222+
def __getitem__(self, cheie: int):
223+
# no error here, method overrides special method
223224
return cheie + 1
224225

225226

tests/functional/a/arguments_differ.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ arguments-differ:41:4:ClassmethodChild.func:Number of parameters was 2 in 'Class
44
arguments-differ:68:4:VarargsChild.has_kwargs:Parameter 'arg' was of type 'bool' and is now of type 'int' in overridden 'VarargsChild.has_kwargs' method
55
arguments-differ:68:4:VarargsChild.has_kwargs:Variadics removed in overridden 'VarargsChild.has_kwargs' method
66
arguments-differ:71:4:VarargsChild.no_kwargs:Parameter 'args' has been renamed to 'arg' in overridden 'VarargsChild.no_kwargs' method
7-
arguments-differ:172:4:SecondChangesArgs.test:Number of parameters was 2 in 'FirstHasArgs.test' and is now 4 in overridden 'SecondChangesArgs.test' method
8-
arguments-differ:222:4:OverridesSpecialMethod.__getitem__:Parameter 'key' has been renamed to 'cheie' in overridden 'OverridesSpecialMethod.__getitem__' method
7+
arguments-differ:172:4:SecondChangesArgs.test:Number of parameters was 2 in 'FirstHasArgs.test' and is now 4 in overridden 'SecondChangesArgs.test' method

0 commit comments

Comments
 (0)