Open
Description
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
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
SVETIK-LION commentedon Mar 16, 2024
Link with code to mypy Playground
https://mypy-play.net/?mypy=latest&python=3.12&gist=c0cce297d05269e23040f01a6cc80c0e
Pierre-Sassoulas commentedon Mar 18, 2024
Thank you for opening the issue. pylint does not understand decorators well, generally.