3

Below code would produce a visual yellow warning in PyCharm, because of the missing arguments of f() inside g().

def f(b):
    return b

def g():
    return f()
#           ^
#           |___ A warning here 

Which is great, since i want to see it and fix it easily whenever i modify the parameters of f().

However if i use a decorator on f(), this warning disappears:

def some_decorator(func):
    def wrapped(*args, **kwargs):
        func(*args, **kwargs)
    return wrapped


@some_decorator
def f(b):
    return b


def g():
    return f()
#            ^
#            |___ no warning

I m guessing this happens since a decorator could be providing those needed arguments to f().

Is there a way to make PyCharm ignore decorators in above scenario and keep on displaying the warning?

user
  • 5,370
  • 8
  • 47
  • 75

1 Answers1

1

Adding g() to either snippet and running gives

TypeError: f() missing 1 required positional argument: 'b'

I cannot answer for sure that you cannot have PyCharm ignore the decorator (check the PyCharm doc), but in my opinion it should not. The f() call in g calls the wrapper, not the wrappee, and the wrapper has an unconstrained generic signature. As you said yourself, the wrapper could (and some wrappers do) manipulate args or kwargs before calling the wrapped function. In other words, I think you are expecting too much. Statics code checks are not a substitute for writing and running tests.

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52