pyupgrade icon indicating copy to clipboard operation
pyupgrade copied to clipboard

Automatically remove try-except blocks.

Open EwoutH opened this issue 7 months ago • 2 comments

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

EwoutH avatar Nov 09 '23 10:11 EwoutH