Skip to content

Optimize effect of disabling import warnings #1336

@erikwright

Description

@erikwright

Steps to reproduce

In a few entry-point scripts some special code is executed that sets up the PYTHONPATH. This code violates the standard import style rules by necessity.

# The following two lines will modify our PYTHONPATH to include PySpark.
from my_project import pyspark_utils  # pylint: disable=wrong-import-order,ungrouped-imports
pyspark_utils.find_pyspark()          # pylint: disable=wrong-import-position

import os
import sys
import pytest

import my_project.shared.session
...

Current behavior

Currently Pylint would require us to either disable wrong-import-position, wrong-import-order, and ungrouped-imports at the file level or apply them to many lines. Yet these errors (which are triggered on many lines) are actually introduced by conflicts with only two lines.

************* Module conftest
conftest.py:5:0 C0413(wrong-import-position) Import "import os" should be placed at the top of the module
conftest.py:6:0 C0413(wrong-import-position) Import "import sys" should be placed at the top of the module
conftest.py:7:0 C0413(wrong-import-position) Import "import pytest" should be placed at the top of the module
conftest.py:9:0 C0413(wrong-import-position) Import "import my_project.shared.session" should be placed at the top of the module
conftest.py:5:0 C0411(wrong-import-order) standard import "import os" comes before "from my_project import pyspark_utils"
conftest.py:6:0 C0411(wrong-import-order) standard import "import sys" comes before "from my_project import pyspark_utils"
conftest.py:9:0 C0412(ungrouped-imports) Imports from package my_project are not grouped

Expected behavior

Ideally, telling Pylint to ignore order/position/grouping errors for a given line would not only ignore when that line is out of place but also ignore that other lines are out of place with respect to that line.

pylint --version output

pylint 1.6.4, 
astroid 1.4.9
Python 3.5.2 (default, Dec  1 2016, 11:51:38) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions