Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python Decorated Function Args

I am facing a weird issue where sometimes my decorated function is receiving arguments and sometime not.

The code is as such:

main.py

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@Authenticator.authenticate_admin
def action_snapshot(username, token, payload):    
    .
    .
    .

authenticator.py

class Authenticator:

@staticmethod
def authenticate_admin(func):
    
    @wraps(func)
    def wrapper(*args, **kwargs):

        print(f"ARGS: {args}")

        # ! Execute function
        return func(*args, **kwargs)
        
    return wrapper

So if i try to call the function in my main like that:

action_snapshot(username, token, payload)

the code works fine and i receive the args.

However if i call it like that:

action_snapshot(
    username=username, 
    token=token
    payload=payload
)

the args is empty.

Any idea why ?

>Solution :

You’re still receiving them, but because you’re passing them as keyword arguments, they’re in kwargs instead of args

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading