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

Changing the number of function arguments when using a decorator does not work. #9505

Open
SVETIK-LION opened this issue Mar 15, 2024 · 2 comments
Labels
Bug 🪲 Decorators Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@SVETIK-LION
Copy link

Bug description

from typing import Callable, Concatenate, ParamSpec, TypeVar

S = TypeVar('S')
P = ParamSpec('P')
RealFun = Callable[Concatenate[S, P], None]
FunWithEvent = Callable[Concatenate[S, int, P], None]


def run_event() -> Callable[[RealFun[S, P]], FunWithEvent[S, P]]:
    def wrapper(func: RealFun[S, P]) -> FunWithEvent[S, P]:
        def wrapped(self: S, event: int, *args: P.args, **kwargs: P.kwargs) -> None:
            func(self, *args, **kwargs)
        return wrapped
    return wrapper


class SomeClass:
    @run_event()
    def orig_fun(self) -> None:
        pass

    def do_call1(self) -> None:
        self.orig_fun(42) # That's OK

    def do_call2(self) -> None:
        self.orig_fun()  # This is an error, MyPy finds that, Nice

    def do_call3(self) -> None:
        self.orig_fun('q')  # This is an error, MyPy finds that, Nice

    def do_call4(self) -> None:
        self.orig_fun(42, 'q')  # This is an error, MyPy finds that, Nice

Configuration

No response

Command used

pylint --rcfile rcfile --disable=similarities --jobs jobs paths

Pylint output

E1121: Too many positional arguments for method call (too-many-function-args)

Expected behavior

If you use a decorator, you can add an argument of a certain type to the function. But if the argument type does not match the one specified in the decorator, an error will occur. It will also be an error if you don't specify an argument at all.

Pylint version

pylint 3.0.4
astroid 3.0.3
Python 3.12.2 (main, Feb 21 2024, 00:00:00) [GCC 13.2.1 20231205 (Red Hat 13.2.1-6)]

OS / Environment

No response

Additional dependencies

No response

@SVETIK-LION SVETIK-LION added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Mar 15, 2024
@SVETIK-LION
Copy link
Author

@Pierre-Sassoulas
Copy link
Member

Thank you for opening the issue. pylint does not understand decorators well, generally.

@Pierre-Sassoulas Pierre-Sassoulas added Bug 🪲 Decorators Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Decorators Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

2 participants