Zac-HD / shed

`shed` canonicalises Python code. Shed your legacy, stop bikeshedding, and move on. Black++
https://pypi.org/project/shed/
GNU Affero General Public License v3.0
343 stars 23 forks source link

Shed requiring two passes when removing import causes ordering confusion #78

Closed jakkdl closed 1 year ago

jakkdl commented 1 year ago

another instance of isort shenanigans making shed require two passes:

-from typing import TYPE_CHECKING, Any, NamedTuple, TypeVar
+from typing import NamedTuple, TYPE_CHECKING, TypeVar
-from typing import NamedTuple, TYPE_CHECKING, TypeVar
+from typing import TYPE_CHECKING, NamedTuple, TypeVar

So in the first pass it removes Any, but also sorts the imports lexically - except on the second pass it resorts them with constants first, then lexically.

Zac-HD commented 1 year ago

Huh. If base isort does that we should report upstream and then bump shed's required version once it's fixed. If not, then we should have some "run again if means we might need to" logic.

jakkdl commented 1 year ago

Ah, it's autoflake getting run after isort that's the culprit here. I opened https://github.com/PyCQA/autoflake/issues/229 - so we either wait for that to be resolved, and/or have shed run autoflake before isort. Doing the latter I think also fixes #75, but maybe there's some other reason you opted to run isort before autoflake.

Zac-HD commented 1 year ago

Probably no reason, let's just swap the order 👍

jakkdl commented 1 year ago

https://github.com/PyCQA/autoflake/pull/232 is now merged - so the temporary fix of running isort twice can be removed as soon as a new version is released