Uploaded image for project: 'Data Management'
  1. Data Management
  2. DM-9596

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

    XMLWordPrintable

    Details

    • Story Points:
      0.25
    • Sprint:
      Alert Production S17 - 4
    • Team:
      Alert Production

      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.

        Attachments

          Activity

          Hide
          rowen 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__ =...")
          

          Show
          rowen 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
          rowen 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
          rowen 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
          ktl 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
          ktl 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
          rowen 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
          rowen 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
          rowen Russell Owen added a comment - Community posting: https://community.lsst.org/t/--all---should-go-before-imports-in-python-code/1769

            People

            Assignee:
            rowen Russell Owen
            Reporter:
            rowen Russell Owen
            Reviewers:
            Kian-Tat Lim
            Watchers:
            John Parejko, John Swinbank, Jonathan Sick, Kian-Tat Lim, Russell Owen, Tim Jenness
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Jenkins

                No builds found.