Pylint: Wrong and confusing message for wrong-import-order in PyLint 1.6.5 and Python 2.7.12

Created on 27 Jan 2017  路  3Comments  路  Source: PyCQA/pylint

Steps to reproduce

  1. Create sample import_order.py file:
"""
This module should not give pylint errors
"""

import mock
import unittest

def test():
    """
    To suppres pylint
    """
    mock.Mock()
    _ = unittest
  1. Run pylint:
> pylint import_order.py
************* Module test_pylint
C:  6, 0: standard import "import unittest" comes before "import mock" (wrong-import-order)

Current behavior

Error message says C: 6, 0: standard import "import unittest" comes before "import mock" (wrong-import-order)

Expected behavior

Error message should say
C: 6, 0: standard import "import unittest" comes after "import mock" (wrong-import-order)
Or
C: 6, 0: "import mock" comes before standard import "import unittest" (wrong-import-order)

pylint --version output

pylint --version
pylint 1.6.5, 
astroid 1.4.9
Python 2.7.12 (default, Jul 29 2016, 11:13:37) 
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)]

Most helpful comment

@rogalski If nothing else, the error message is wrong. it should be:

C: 6, 0: "import mock" comes before standard import "import unittest" (wrong-import-order)

All 3 comments

Why you assume that errors shouldn't be triggered? IIRC, isort groups imports as in:

  1. built-ins
  2. 3rd-party packages
  3. project imports

mock belongs to second tier, unittest to first.

@rogalski If nothing else, the error message is wrong. it should be:

C: 6, 0: "import mock" comes before standard import "import unittest" (wrong-import-order)

@rogalski yes, your're right, mock should actually go after unittest. So error is being triggered correctly.

But the error message is wrong and confusing.

So I've updated issue title and expected behavior section with message suggested by @degustaf and another option.

Was this page helpful?
0 / 5 - 0 ratings