Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flag to skip for __init__.py files #226

Closed
ErikBjare opened this issue Oct 13, 2022 · 3 comments · Fixed by #228
Closed

Flag to skip for __init__.py files #226

ErikBjare opened this issue Oct 13, 2022 · 3 comments · Fixed by #228
Labels
bug Something isn't working

Comments

@ErikBjare
Copy link
Contributor

ErikBjare commented Oct 13, 2022

Since __init__.py files tend to have "unused" imports, autoimport will happily remove them.

This is fine if the script is run from somewhere where we can easily filter out the __init__.py (like in a Makefile), but becomes unwieldy when run through "fix-on-save" in your editor.

autoflake has solved the same problem with a --ignore-init-module-imports flag, perhaps we could add the same to autoimport?

Edit: should've opened this as a feature request, sry.

@ErikBjare ErikBjare added the bug Something isn't working label Oct 13, 2022
ErikBjare added a commit to ErikBjare/autoimport that referenced this issue Oct 13, 2022
ErikBjare added a commit to ErikBjare/autoimport that referenced this issue Oct 13, 2022
ErikBjare added a commit to ErikBjare/autoimport that referenced this issue Oct 13, 2022
@lyz-code
Copy link
Owner

lyz-code commented Oct 14, 2022

Hi @ErikBjare thanks for taking the time to open not only an issue but also for making the PR. I'm fine with merging it but just a question. If you do imports in __init__.py files, shouldn't you also add the imported objects to the __all__ variable? If you do so, then autoimport won't delete the imports.

I guess there are more keystrokes for the same result, although for me it adds clarity.

BTW, it's an honor to have your name under the contributors of the project, I <3 activitywatch!

lyz-code added a commit that referenced this issue Oct 14, 2022
feat: added --ignore-init-modules flag (fixes #226)
@lyz-code
Copy link
Owner

Available since 1.3.0 thanks to @ErikBjare

@ErikBjare
Copy link
Contributor Author

Thanks for the swift merge!

If you do imports in init.py files, shouldn't you also add the imported objects to the all variable? If you do so, then autoimport won't delete the imports.

I guess there are more keystrokes for the same result, although for me it adds clarity.

Yeah, didn't think of that as a workaround, but I almost never use __all__ and don't really have a good reason to change it in all my codebases.

BTW, it's an honor to have your name under the contributors of the project, I <3 activitywatch!

Yay, that makes me happy. Thank you ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants