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

Ignore F401 in __init__.py #109

Closed
wants to merge 1 commit into from
Closed

Ignore F401 in __init__.py #109

wants to merge 1 commit into from

Conversation

jobh
Copy link

@jobh jobh commented Apr 25, 2024

Ruff by default ignores unused imports in __init__.py, since they are often (usually?) intended to be public and removing them breaks code elsewhere. This PR makes shed do the same.

https://docs.astral.sh/ruff/settings/#lint_ignore-init-module-imports

@Zac-HD
Copy link
Owner

Zac-HD commented Apr 25, 2024

I'm actually pretty fond of the "no, you actually do need to add them to __all__ or import ... as" approach here - using a very strict, no-opt-out configuration is basically the whole point of shed in the first place. In the last few months it's become quite easy to build your own equivalent just by configuring ruff, too.

@jobh
Copy link
Author

jobh commented Apr 25, 2024

Hey, I buy that, so take what follows with a pinch of salt. I'd like to argue the opposite side in case it resonates.

A formatter, opinionated or not, should avoid breaking code. An opinionated formatter might rewrite the file to add __all__ to make it explicit, or it might cop out (like ruff's default) and just complain about it, but this is a case where just removing the imports is quite likely to break things. Sure, in python you can't safely remove anything from any namespace, it's just that this particular one has a lot higher risk, and hence it makes sense to special-case it.

@Zac-HD
Copy link
Owner

Zac-HD commented Apr 26, 2024

I do appreciate your engagement on this question, and I've gone back and forth on it myself!

Ultimately I think I'm going to stick with the breaking-removal approach here: shed does many potentially-unsafe transformations, just just autoformatting, and I don't mind pushing people towards the use-__all__ style and relying on vcs history to recover if it was a breaking change.

@Zac-HD Zac-HD closed this Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants