Skip to content

Azureblade3808/py-deferrer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fancy defer for Python >= 3.12

Python package Coverage Status

Installation and usage

Installation

You may install deferrer by running pip install deferrer.

Usage

There are two designed ways to use defer. You may use either of them, or mix them up.

Sugarful

>>> 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

Sugarless

>>> 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