PyCQA / flake8-import-order

Flake8 plugin that checks import order against various Python Style Guides
GNU Lesser General Public License v3.0
278 stars 72 forks source link

Clarify in documentation how modules are determined to be of a certain type #70

Closed johnthagen closed 8 years ago

johnthagen commented 8 years ago

From the Limitations section of the docs:

The classification of an import as being non-stdlib of some kind depends on that package actually being installed.

But looking at the code in _import_type() it seems like what really happens is that if the module doesn't match the others, it's considered to be third party. This was confusing at first because based on the documentation I tried installing/uninstalling third party packages to try to fix issues:

        else:
            # Not future, stdlib or an application import.
            # Must be 3rd party.
            return IMPORT_3RD_PARTY

Next:

You will want to set the application-import-names option to a comma separated list of names that should be considered local to your application. These will be used to help categorise your import statements into the correct groups.

Also from _import_type(), it would be helpful to new users to mention that relative imports are always considered local:

        if name is None:
            # relative import
            return IMPORT_APP
...
        elif isinstance(node, ast.ImportFrom) and node.level > 0:
            return IMPORT_APP_RELATIVE

I realize these are somewhat implementation details, but I think they really help new comers determine why many of the locals are properly recognized, but not others.