# __all__ = ... should go after from __future__ import and before any other includes

XMLWordPrintable

#### Details

• Type: Improvement
• Status: Done
• Resolution: Done
• Fix Version/s: None
• Component/s:
• Labels:
• Story Points:
0.25
• Sprint:
• Team:

#### Description

The Python coding standards say that __all__ = ... should go after all imports:
https://developer.lsst.io/coding/python_style_guide.html#standard-code-order-should-be-followed

However, PEP8 specifically states in Module level dunder names that it should go before any imports except from __future__ import ....

In my opinion the PEP8 standard makes the code more readable (by advertising the public symbols right away) and I can't think of any good reason to violate it (other than past history). I suggest we updated our coding standards accordingly.

#### Activity

Hide
Russell Owen added a comment - - edited

The bullet list at https://developer.lsst.io/coding/python_style_guide.html#standard-code-order-should-be-followed presently reads:

 3. Module-level docstring 4. Imports 5. __all__ statement, if any 

 3. Module-level docstring 4. from __future__ import absolute_import, division, print_function 5. __all__ statement, if any 6. Imports (other than "from __future__ import...", which must appear before "__all__ =...") 

Show
Russell Owen added a comment - - edited The bullet list at https://developer.lsst.io/coding/python_style_guide.html#standard-code-order-should-be-followed presently reads: 3. Module-level docstring 4. Imports 5. __all__ statement, if any I suggest that instead it read: 3. Module-level docstring 4. from __future__ import absolute_import, division, print_function 5. __all__ statement, if any 6. Imports (other than "from __future__ import...", which must appear before "__all__ =...")
Hide
Russell Owen added a comment -

Pull request made. I also removed mention of test suites at the end (as per a "fixme"), but that is a second commit and can be easily dropped if desired.

Show
Russell Owen added a comment - Pull request made. I also removed mention of test suites at the end (as per a "fixme"), but that is a second commit and can be easily dropped if desired.
Hide
Kian-Tat Lim added a comment -

Looks OK, with one possible change to the wording (up to you whether to make it).

Do current linting/autoformatting tools conform to this, or do they leave this unchecked?

Since this represents a change to current practice, please publicize it on Community.

Show
Kian-Tat Lim added a comment - Looks OK, with one possible change to the wording (up to you whether to make it). Do current linting/autoformatting tools conform to this, or do they leave this unchecked? Since this represents a change to current practice, please publicize it on Community.
Hide
Russell Owen added a comment -

I updated the wording to Imports (other than... (I won't type it all out here, since JIRA preformatted text is so painful).

Current flake8 does conform to the new/current rule and autopep8 at least leaves correct code unmolested.

There are old versions of flake8 that do not conform to this rule, and I don't know when it changed. I don't know anything about other linters,

Show
Russell Owen added a comment - I updated the wording to Imports (other than... (I won't type it all out here, since JIRA preformatted text is so painful). Current flake8 does conform to the new/current rule and autopep8 at least leaves correct code unmolested. There are old versions of flake8 that do not conform to this rule, and I don't know when it changed. I don't know anything about other linters,
Hide
Russell Owen added a comment -
Show
Russell Owen added a comment - Community posting: https://community.lsst.org/t/--all---should-go-before-imports-in-python-code/1769

#### People

Assignee:
Russell Owen
Reporter:
Russell Owen
Reviewers:
Kian-Tat Lim
Watchers:
John Parejko, John Swinbank, Jonathan Sick, Kian-Tat Lim, Russell Owen, Tim Jenness