3 ms·
I liked contracts in Racket, so ported some of it to Python. These checks can very well be done inside the called function but decorators enable a more declarat
by irahul 15y ago
I liked contracts in Racket, so ported some of it to Python. These checks can very well be done inside the called function but decorators enable a more declarative style.
- grncdr 15y agoVery nice. I did something very similar for an RPC server I wrote, but it's less general and relies on the ORM (SQLAlchemy). Essentially, it turns database id's into the mapped objects, checks the objects against the constraints declared as arguments to the decorator (much like this module), and then passes the mapped objects in to the original function in place of the id. It's proven to be a very useful pattern, but I'll probably use this library instead for future projects.