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!)

I also noticed that a 2 spaces indentation is used (whereas PEP8 says the standard is 4 spaces) but that's a detail. If you want to change that, I can submit another pull request.