Cleanup and fix for a mutability issue

Some cleanup (all imports at the top, unused imports, unused exception var, trailing spaces) and a little fix for a mutability issue with the `extra` parameter default value.

Because it was set to `{}`, different instances of this class had the same instance of the extra attribute. (immutable default parameters can be pretty dangerous in Python!)