asottile / pyupgrade

A tool (and pre-commit hook) to automatically upgrade syntax for newer versions of the language.
MIT License
3.46k stars 178 forks source link

auto-remove things from TYPE_CHECKING blocks #849

Open asottile opened 1 year ago

asottile commented 1 year ago

for instance in --py38-plus:

-if TYPE_CHECKING:
-    from typing import Protocol
-else:
-    Protocol = object
+from typing import Protocol

that's the most complex mode -- some of them are simpler (just imports)

Mahdi-Hosseinali commented 2 months ago

This is a bad idea. If you use | between types then it should be None | 'Protocol' which means Protocol is not used. Then the other linters start complaining about unused imports.

asottile commented 2 months ago

what are you even talking about