You know you can simply pass functions as parameters, right? def lock(func, *args): # ...setup result = func(*args) #... teardown return result.
And then, with 3 more lines you do a decorator out of that def locked(func): # <'lock' body as above> return lock in the end: @locked def mythings(): # code that runs 'locked' ... On Mon, 13 Jul 2020 at 17:48, <redrad...@gmail.com> wrote: > Today I think about lambda in Python and what if we introduce the new > syntax: > ```python > def lock(*args, closure): > # Do some stuff > closure() # Call closure > # Finish stuff > > if __name__ == '__main__': > lock(): > # Do some things here is thread safe > ``` > > This feature could be very similar as in `Kotlin` inline functions > https://kotlinlang.org/docs/reference/inline-functions.html > _______________________________________________ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/HAIFGFE5YUCGLEWFPT3K2N3H6WBK4KQ7/ > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/QTLUKWVALORYHCS23SUHN4GSEAVOGHZS/ Code of Conduct: http://python.org/psf/codeofconduct/