You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Similar to #7778, where having a function that returns a decorator inside a class without a self parameter
is not possible.
To Reproduce
I have this setup to be able to do this inside a class:
@log('hello world')
def method(self):
...
fromfunctoolsimportwrapsfromtypingimportCallableclassMyClass:
deflog(text: str):
deflog_decorator(func: Callable) ->Callable:
@wraps(func)deflog_wrapper(self):
func(self)
print(text) # Passed as param in logreturnlog_wrapperreturnlog_decorator@log('print this')deftest(self) ->None:
print('word')
foo=MyClass()
foo.test()
Expected Behavior
mypy should not find any errors with this.
Actual Behavior
mypy test_concept.py
test_concept.py:5: error: Self argument missing for a non-static method (or an invalid type for self) [misc]
Found 1 error in 1 file (checked 1 source file)
Your Environment
Mypy version used: mypy 1.4.1 (compiled: yes)
Mypy command-line flags: None
Mypy configuration options from mypy.ini (and other config files): None
Python version used: 3.10.0
The text was updated successfully, but these errors were encountered:
I'm going to say this is out of scope. This use case is very rare, and any reasonable solution is going to make it a lot harder for mypy to correctly report cases where the user forgot to add self (a common mistake).
Bug Report
Similar to #7778, where having a function that returns a decorator inside a class without a self parameter
is not possible.
To Reproduce
I have this setup to be able to do this inside a class:
Expected Behavior
mypy should not find any errors with this.
Actual Behavior
Your Environment
mypy.ini
(and other config files): NoneThe text was updated successfully, but these errors were encountered: