[Python-Dev] PEP 8 updates/clarifications
Guido van Rossum
guido at python.org
Tue Dec 13 05:43:14 CET 2005
On 12/12/05, skip at pobox.com <skip at pobox.com> wrote:
>
> >> I looked at that too, but most of these didn't jump out at me. I'll
> >> copy in the parts that aren't already in PEP 8 that seem possible:
> >>
> >> From-imports should follow non-from imports. Dotted imports should
> >> follow non-dotted imports. Non-dotted imports should be grouped by
> >> increasing length, while dotted imports should be grouped roughly
> >> alphabetically.
> >> This seems too complex to me for PEP 8.
>
> Barry> Really? ISTR adopting this convention from Guido, but I'm not
> Barry> 100% sure about that. After having used it for several years
> Barry> now, I do really like this style, but I'm willing to leave the
> Barry> recommendation out of PEP 8.
>
> This is subjective enough that I would think some rationale explaining this
> convention should be given. Personally, I group imports into three sections
> as follows:
>
> * Python core modules/packages
>
> * Third-party modules/packages
>
> * Local modules/packages
>
> I can't explain why I do it that way. I guess it just satisfies some inner
> hobgoblin.
This is what I recommend too, and PEP 8 should recommend this.
While I admit to a kind of secret enjoyment when I see the standard
library module imports arranged by increasing length, I don't think
that ought to be put in the PEP. (I remember once seeing a friend's
books arranged by size on their shelves and finding it bizarre. You
should have the same feeling when you see imports arranged that way.)
A more rational approach would be to do them alphabetically.
Putting the from...import ones last makes sense if only because it's
not obvious where they fit in the alphabetization.
Dotted non-from imports (e.g. import test.pystone) are rare enough
that they don't deserve a special rule; if you want me to give a rule,
I think they should be mixed in with the undotted ones,
alphabetically.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list