- put comments on previous line to let the automatic code formatting do its job
- save some indentation levels
- add a few typehints
- use f-strings
- tx_cache_put is always called with a valid Transaction, no need to check for `tx is not None`
- move imports to the top of the file (they are always imported anyway by other modules, and multiple imports add no significant additional cost)