You may install deferrer
by running pip install deferrer
.
There are two designed ways to use defer
. You may use either of them, or mix them up.
>>> from deferrer import defer
>>> def f():
... defer and print(0)
... defer and print(1)
... print(2)
... defer and print(3)
... defer and print(4)
>>> import sys
>>> if sys.version_info < (3, 12):
... from deferrer import defer_scope
... f = defer_scope(f)
>>> f()
2
4
3
1
0
>>> from deferrer import defer
>>> def f():
... defer(print)(0)
... defer(print)(1)
... print(2)
... defer(print)(3)
... defer(print)(4)
>>> import sys
>>> if sys.version_info < (3, 12):
... from deferrer import defer_scope
... f = defer_scope(f)
>>> f()
2
4
3
1
0