Here are many answers on how to determine if a python decorator is used with or without arguments. They usually look like this:
class MyDecorator(object): def __init__(self, *args): if len(args) == 1 and callable(args[0]):
But now I have the following use case:
@MyDecorator(lambda x:2*x) def foo(): pass
This is incorrectly defined as a case with no arguments.
Is there any way to detect this situation?
[edit: added missing parameter "self"]
source share