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

Group "from" and "import" lines for the same module #16

Closed
bukzor opened this issue Jun 21, 2016 · 2 comments
Closed

Group "from" and "import" lines for the same module #16

bukzor opened this issue Jun 21, 2016 · 2 comments

Comments

@bukzor
Copy link

bukzor commented Jun 21, 2016

Input:

import array
import os
import re

from datetime import datetime
from os.path import join
from zipfile import ZipFile

Current output:

import array
import os
import re
from datetime import datetime
from os.path import join
from zipfile import ZipFile

Desired output:

import array
from datetime import datetime
import os
from os.path import join
import re
from zipfile import ZipFile

This gives a concrete advantage:

  • All references to a particular package are in a single, specific place, regardless of import style.

This makes working with the code slightly easier: When refactoring, finding all imports of a package requires just one alphabetical search. When reviewing patches, changes to a particular package will be confined to a single diff-block, even if the import style changes.

There's prior art in the openstack style guide. Most other style guides are either ambiguous or completely unspecified on this fine point. What's more, the "Desired" block passes one of the pylint checks, while the "Current" doesn't.

Most importantly though, this accords with my intuition. I feel it has the same driving force as our trailing-comma policy; among essentially-equal formattings, pick the one that provides the lowest barrier to refactoring.

I'll implement the change if we can agree on the policy.

@asottile
Copy link
Owner

That's not how it is specced here. If you want to introduce a non default option which enables this feel free to open a pull request

@bukzor
Copy link
Author

bukzor commented Jun 21, 2016

The request is to agree on an updated spec...

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

No branches or pull requests

2 participants