pep585-upgrade icon indicating copy to clipboard operation
pep585-upgrade copied to clipboard

Shebang is not respected

Open rominf opened this issue 4 years ago • 3 comments

Input:

#!/usr/bin/env python3
from typing import AbstractSet

s: AbstractSet

Output:

from collections.abc import Set
#!/usr/bin/env python3

s: Set

I didn't prepare the fix yet, but I think that the best solution would be to save the first occurrence of non-comment, non-docstring expressions while scanning AST and put the imports before that. What do you think?

rominf avatar Mar 17 '21 18:03 rominf

I see that I never responded here, sorry about @rominf. Would you still like to fix this? No pressure 🙂

If you do, I think your suggestion sounds good 👍

sondrelg avatar May 26 '21 20:05 sondrelg

Sorry, I'm not interested (at least for now), because of the old version of MyPy in repos, which doesn't support pep585.

rominf avatar Jun 03 '21 13:06 rominf

@rominf Hack: If you're using isort in the pre-commit, add pep5-updgrade before isort. The upgrade script will add import at the top and isort will properly order the imports. Also the PR idea can be leveraged to check for shebang line.

kracekumar avatar Jun 03 '21 20:06 kracekumar

I'm officially deprecating this project, as pyupgrade now fills the gap this once did. The package can still be used, but I'm not intending to spend any more time maintaining it, so closing this for now 🙂

sondrelg avatar Oct 07 '22 01:10 sondrelg