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

Intermixed 1st and 3rd party imports in pep8 mode cause TypeError #76

Closed ulope closed 8 years ago

ulope commented 8 years ago

In pep8 mode code files containing standard library imports after third party ones cause a TypeError in ImportOrderChecker.check_order.build_str.

Minimal example:

test.py:

import thirdparty
import sys
~ # pip install flake8 flake8-import-order
[...]
Successfully installed flake8-2.6.2 flake8-import-order-0.8 mccabe-0.5.0 pep8-1.7.0 pycodestyle-2.0.0 pyflakes-1.2.3

~ # flake8 --import-order-style=pep8 test.py
Traceback (most recent call last):
  File "/Users/ulo/Envs/tmp-686c3c2aab00eaf/bin/flake8", line 11, in <module>
    sys.exit(main())
  File "/Users/ulo/Envs/tmp-686c3c2aab00eaf/lib/python3.5/site-packages/flake8/main.py", line 36, in main
    report = flake8_style.check_files()
  File "/Users/ulo/Envs/tmp-686c3c2aab00eaf/lib/python3.5/site-packages/flake8/engine.py", line 181, in check_files
    return self._retry_serial(self._styleguide.check_files, paths=paths)
  File "/Users/ulo/Envs/tmp-686c3c2aab00eaf/lib/python3.5/site-packages/flake8/engine.py", line 172, in _retry_serial
    return func(*args, **kwargs)
  File "/Users/ulo/Envs/tmp-686c3c2aab00eaf/lib/python3.5/site-packages/pycodestyle.py", line 1877, in check_files
    runner(path)
  File "/Users/ulo/Envs/tmp-686c3c2aab00eaf/lib/python3.5/site-packages/flake8/engine.py", line 126, in input_file
    return fchecker.check_all(expected=expected, line_offset=line_offset)
  File "/Users/ulo/Envs/tmp-686c3c2aab00eaf/lib/python3.5/site-packages/pycodestyle.py", line 1608, in check_all
    self.check_ast()
  File "/Users/ulo/Envs/tmp-686c3c2aab00eaf/lib/python3.5/site-packages/pycodestyle.py", line 1555, in check_ast
    for lineno, offset, text, check in checker.run():
  File "/Users/ulo/Envs/tmp-686c3c2aab00eaf/lib/python3.5/site-packages/flake8_import_order/flake8_linter.py", line 52, in run
    for error in self.check_order():
  File "/Users/ulo/Envs/tmp-686c3c2aab00eaf/lib/python3.5/site-packages/flake8_import_order/__init__.py", line 289, in check_order
    first_str = build_str(k)
  File "/Users/ulo/Envs/tmp-686c3c2aab00eaf/lib/python3.5/site-packages/flake8_import_order/__init__.py", line 283, in build_str
    if level >= 0:
TypeError: unorderable types: NoneType() >= int()
pgjones commented 8 years ago

Thanks, this is very clear. I'll look to fix.