Junior
Typed decorator with parameters
livecode
Task condition
Write a typed decorator with parameters. It should add an argument to the decorated function. Example:
from threading import Lock
my_lock = Lock()
@locked(my_lock)
def function1(lock: Lock, arg: int) -> int:
return arg + 1
@locked(my_lock)
def function2(lock: Lock, name: str, surname: str) -> str:
return name + surname
# Inside 'locked', the code roughly looks like this:
# python
# with passed_lock:
# return function(passed_lock, *args, **kwargs)
# The star question: how to make it both a decorator and a context manager?
# The star question: how to make it both a decorator and a context manager?
# The star question: how to make it both a decorator and a context manager?
def locked(): # TOOO