from typing import Callable
class Formatter:
def decorator(self, main_function: Callable) -> Callable:
def wrapper(*args, **kwargs):
print("Inside the decorator")
return main_function(*args, **kwargs)
return wrapper
Which in this case, is a class called Formatter that has an instance method that acts as decorator, called decorator.
Now, create a method called foo, and decorate it using the decorator instance method, but, because in this case we need an instance of the Formatter class to use this decorator, we need to make the following code:
@Formatter().decorator
def second_foo():
print("Inside the second_foo function")
if __name__ == "__main__":
second_foo()
And it works, but the called decorator is marked in red, as if it were a mistake.
Is this an error of the editor, or do I need to define some type hints?
Steps to Reproduce:
Which in this case, is a class called
Formatter
that has an instance method that acts as decorator, calleddecorator
.foo
, and decorate it using thedecorator
instance method, but, because in this case we need an instance of theFormatter
class to use this decorator, we need to make the following code:And it works, but the called decorator is marked in red, as if it were a mistake.
Is this an error of the editor, or do I need to define some type hints?