-
Notifications
You must be signed in to change notification settings - Fork 912
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
Add option to move module level dunders to top of file #9324
Comments
For reference, isort already has this an option so we might just be able to add it to the isort rules: PyCQA/isort@44e3b5d |
Does that open sort the members of |
That is a different rule that is tracked by #1198. The title of this issue is a bit confusing. Bad: """Dummy module"""
from __future__ import annotations
import os
__all__ = ["foo"] Good: """Dummy module"""
from __future__ import annotations
__all__ = ["foo"]
import os @nstarman , I think the title of this issue should be changed to something like "Add option to move module level dunders to top of file"
The former. |
It's worth noting that before 2016 the PEP8 mandated the opposite,
This was changed to the current text in but the style checkers only relaxed the previous rule instead of implementing the new one PyCQA/pycodestyle#523 PyCQA/pycodestyle#615 , so there's been no pressure to change it in existing codebases. It seems like most Python code follows the older convention still, since people tend to go by whatever their style checker / formatter says instead of reading PEP8 themselves. I don't know if there's any other PEP8 suggestion that so wildly differs from what's done in practice. |
__all__
according to PEP8
In https://pep8.org/#module-level-dunder-names it says that
__all__
"should be placed after the module docstring but before any import statements except from__future__
imports".It would be great to have an isort-style rule that implements the PEP8 suggestion.
There are definitely cases when
__all__
shouldn't be moved to above the imports, e.g. when it is dynamically defined from the imports, but if__all__
contains only strings then it should be safe to move.The text was updated successfully, but these errors were encountered: