pyupgrade
pyupgrade copied to clipboard
Automatically remove try-except blocks.
When currently applying pycharm on a Python 2.7-compatible codebase, a few of such cases pop up:
try:
from collections.abc import Iterable
except ImportError:
- from collections import Iterable
+ from collections.abc import Iterable
It would be useful if pyupgrade could detect if the code in both the try
and except
end up identical, and if so, remove the block.
In that case, the diff should become:
-try:
- from collections.abc import Iterable
-except ImportError:
- from collections import Iterable
+from collections.abc import Iterable