I'm not sure how to have specific type for decorator's inner function which takes in a function of type Callable[..., Any]. I have the following example written:
from typing import Callable, Any
from threading import Thread, Lock
def synchronized(function: Callable[..., Any]):
lock = Lock()
def innerFunction( -- whatAreTheParametersWithTypeHere -- ):
lock.acquire()
function( -- whatAreTheParametersWithTypeHere -- )
lock.release()
return innerFunction
class Test:
def __init__(self):
self.__value: int = 0
@synchronized
def threadFunc(self):
self.__value = 0
for _ in range(10000000):
self.__value += 1
print(self.__value)
def main():
testObj = Test()
for _ in range(100):
thread = Thread(target=testObj.threadFunc, args=())
thread.start()
if __name__ == "__main__":
main()