0

I installed pylint on my PC. But while I'm writing some code, for instance:

def my_logger(original_func):
    import logging
    logging.basicConfig(filename = f'{original_func.__name__}.log', level = logging.INFO)

    def wrapper(*args, **kwargs):
        logging.info(f'Ran with {*args} and {**kwargs}.')

        return original_func(*args, **kwargs)

    return wrapper

Pylint raises syntax-error and underlines keyword 'def':

invalid syntax(<fstring>, line 1) pylint syntax-error [1,1]

Gama11
  • 31,714
  • 9
  • 78
  • 100

1 Answers1

0

*args and **kwargs are not expressions; they are syntax restricted to certain contexts (such as function calls, function declarations, array literals, multiple assignments etc). The f-string {...} interpolator expects an expression.

This works:

logging.info(f'Ran with {args} and {kwargs}.')
Amadan
  • 191,408
  • 23
  • 240
  • 301