-2

I am trying to write a dummy wrapper in the case where some module is not installed. I have found this here:

from functools import wraps

def jit(*args0, **kwargs0):
    def outer(func):
        @wraps(func)
        def inner(*args, **kwargs):
            return func(*args, **kwargs)
        return inner
    return outer

but I would like the wrapper to be as lightweight as possible (even if functools is standard, it is too much just for doing nothing), and to accept multiple parameters:

@jit(nopython=True)
def myFunction(*args, **kwargs):
    return None

i have tried something like this :

def jit(func, nopython, **kwargs2):
    def inner(*args, **kwargs):
        return func(*args, **kwargs)
    return inner    

But I get this exception :

TypeError: jit() missing 1 required positional argument: 'func'   

Is there a standard way to create a simple wrapper like this?

Kramer84
  • 47
  • 6

1 Answers1

0

Answer based on meta-decorators:

def jit(*args0, **kwargs0):
    def wrapper(func):
        def inner(*args, **kwargs):
            return func(*args, **kwargs)
        return inner
    return wrapper

The first code snippet was entirely valid, and the functools.wrap method not needed.

Kramer84
  • 47
  • 6