tweekmonster / impsort.vim

Sort and highlight Python imports in Vim
MIT License
37 stars 6 forks source link

try except imports add unnecessary line #17

Closed DanCardin closed 7 years ago

DanCardin commented 7 years ago
try:
    import os
except:
    pass

I would think should stay as-is, but gets transformed to

try:
    import os

except:
    pass
tweekmonster commented 7 years ago

Sorry for the delay. There's a special case for this if you use except ImportError:, which is better to use and more common. You would otherwise mask exceptions that are caused by programming errors within the module if it does exist.

I don't want this plugin to be the syntax police, so I'll think about this for a bit. But, I'm torn because this could be annoying enough to keep people from doing this (which wasn't the intention) 😜

@blueyed WDYT?

blueyed commented 7 years ago

I like that it is annoying somehow, but it should rather add a comment there then also.. ;) And because of this it's probably better to special-case all except lines.

tweekmonster commented 7 years ago

The reasoning I was going with is that the gap would naturally exist if there's more code in the try block. For example:

try:
    import mod

    mod.do_something()
except:
    pass

But, I still don't want this plugin to be the syntax police, so I'll go ahead and have it close the gap. I want people to have the same rights that I have to shoot myself in the foot without everyone being all uppity about it.

blueyed commented 7 years ago

@tweekmonster Understood. Thanks!