Comment
Comment by chronial
I think I prefer this version:
It might need a bit more knowledge about context managers [1], but it feels less magic and more explicit to me – i.e. more pythonic :). But it also contains the assumption that db.connection already returns the connection. If that is not true, a bit more housekeeping is needed:
[1] https://docs.python.org/3/library/stdtypes.html#typecontextm...