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

False positive with arguments-differ rule in overridden overloaded methods in subclass #10186

Open
vtgn opened this issue Jan 16, 2025 · 0 comments
Labels
Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling

Comments

@vtgn
Copy link

vtgn commented Jan 16, 2025

Bug description

Pylint reports false positive with the arguments-differ rule for abstract overloaded static methods declared in a super class, implemented in overridden overloaded static methods in a subclass. The same warnings are generated even if the overridden methods are not abstract in the super class, or just instance methods instead of static methods.

Simple example:

from abc import ABC, abstractmethod
from typing import Literal, overload


class A(ABC):

    @staticmethod
    @abstractmethod
    @overload
    def func(*, b: Literal[True]): ...

    @staticmethod
    @abstractmethod
    @overload
    def func(*, b: Literal[False], p: int): ...

    @staticmethod
    @abstractmethod
    @overload
    def func(*, s: str): ...

    @staticmethod
    @abstractmethod
    def func(*, b: bool | None = None, p: int | None = None, s: str | None = None):
        """The implementation"""


class B(A):

    @staticmethod
    @overload
    def func(*, b: Literal[True]): ...

    @staticmethod
    @overload
    def func(*, b: Literal[False], p: int): ... # WARNING: Number of parameters was 1 in 'A.func' and is now 2 in overriding 'B.func' method Pylint(W0221:arguments-differ)

    @staticmethod
    @overload
    def func(*, s: str): ... # WARNING: Number of parameters was 1 in 'A.func' and is now 1 in overriding 'B.func' method Pylint (W0221:arguments-differ)

    @staticmethod
    def func(*, b: bool | None = None, p: int | None = None, s: str | None = None):
        print(f"Params are '{b}' and '{p}' and {s}.")

It seems Pylint only takes into account the first declaration of the method in the abstract class, but even like this, it generates irrational messages like the second one in the example above.

There are several other issues about this rule, but I have seen none about this specific case.

Configuration

Default configuration of Pylint VSCode Plugin.

Command used

Pylint VSCode plugin.

Pylint output

See in the comments of the example above.

Expected behavior

No warning should be generated because the code is correct.

Pylint version

VSCode extension: ms-python.pylint 2024.0.0 / Pylint version 3.2.7
Python: 3.13.0

OS / Environment

Win 11 Professional

Additional dependencies

@vtgn vtgn added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jan 16, 2025
@vtgn vtgn changed the title False positive with arguments-differ rule in subclass implementation False positive with arguments-differ rule in overridden overloaded methods in subclass Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling
Projects
None yet
Development

No branches or pull requests

1 participant