Decorated python function with parameters only used by the decorator are seen as unused

Viewed 16

I have a number of functions that are RPC calls and all have to prepare several things before the main task and to do some cleanup afterwards. Especially their first two parameters are logname and password which are needed to setup user data (properties, rights etc.).

So I decided to build a decorator called @rpc_wrapper which performs these tasks. This wrapper is now working fine for more than a year. The only drawback is that the inspect code function of PyCharm – I think other linters will behave similar – complains about the parameters logname and password which are never used inside of the function but only by the decorator.

How can I get rid of these complaints?

One way might be to insert a line

    assert (logname, password)

at the start of each function. But I think that's not the real deal because decorators are made to avoid replications.

Is there a cleaner solution?

Edited

Here is the (simplified) decorator:

def rpc_wrapper(func):
    @wraps(func)
    def wrapper(login=None, pwd=None, *args, **kwargs):
        doCleanup = True
        try:
            doCleanup = setupUser(login, pwd)
            return func(login, pwd, *args, **kwargs)
        except Exception:
            logging.exception('**<#>')
            raise Exception('999: internal error')
        finally:
            if doCleanup:
                cleanup()
    return wrapper

And a decorated function:

@rpc_wrapper
def ping(login: str = None, pwd: str = None):
    return 'pong'

or another simple one:

@rpc_wrapper
def echo(login: str = None, pwd: str = None, msg: Any = 'message'):
    return msg
0 Answers
Related