Abstracting Control Flow
hackflow.com
hackflow.com
The end result might look better in something like Lisp or Ruby, but I don't think it's a great tradeoff in Python.
By the way, first piece of code can become much more hairy with time.
The final result is broke up in nicely referentially transparent functions, making testing or refactoring more trivial. Also, the main body reads as a DSL, a programmer can pick this code and more easily figure out what it does, which is easier to reason about.
Chapter 2.2.3: Sequences as Conventional Interfaces,
http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-15.html...
"The value of expressing programs as sequence operations is that this helps us make program designs that are modular, that is, designs that are constructed by combining relatively independent pieces."
A couple things look wrong in the OP's last snippet: shouldn't
ignore_small = ignore(ImageTooSmall)
be ignore_small = lambda call: ignore(call, ImageTooSmall)
and similarly for the definition of http_retry?I've seen a @decorator function defined by Peter Norvig before, but it only propagated metadata, it didn't change the usual functionality of its argument.
But basically it just helps avoiding nesting functions, a common boilerplate when writing decorators.