This seems very useful!
The behaviour of auto-imports https://github.com/CZ-NIC/pz#auto-import seems bit scary:
> Caveat: When accessed first time, the auto-import makes the row reprocessed. It may influence your global variables. Use verbose output to see if something has been auto-imported.
It sounds like this could cause some very subtle bugs. Maybe a strong and clear warning when a line is being reprocessed would help.
I wrote a similar tool a while back. My solution for this was to statically analyse the input to discover unused names. The cool part of doing transformations statically is that you're able to see the exact Python code you'd run without running it, e.g. `pyp --explain x[:5]`.
https://github.com/hauntsaninja/pyp