Skip to content

Linting more than one dir or package, can hide errors or cause wrong errors #2966

Open
@MarKett

Description

@MarKett

Calling pylint with more than one dir or package leads to new entries in sys.path. This will hide import-errors of modules that should not be reachable or can even hide other modules with the same name in another folder (or python internals like the logging module as shown in this example).

This minimal example shows two problems.

Steps to reproduce

  1. Create the following folders / packages / files:
|- a_lib
    |- logging.py
    |- not_logging.py
|- another_lib
    |- uses_logging.py
  1. Write into another_lib/uses_logging.py (other files can be left empty):
from logging import handlers # expected: no error
import not_logging           # expected: import-error
  1. Call:
    python -m pylint --errors-only a_lib another_lib

Current behavior

  • The first line in uses_logging.py raises a no-name-in-module

This happens, because pylint adds the paths to parse to the sys.path so this module is found before the python logging module

  • The second line raises no error

Because it can import not_logging from a_lib that was added to the python path from pylint

Expected behavior

  • The first line in uses_logging.py should raise no error, because pylint should be able to find the builtin logging module from python and its handler
  • The second line should raise an import-error because it can't import not_logging from a_lib without specifying the relative path

pylint --version output

python -m pylint --version output
main.py 2.3.1
astroid 2.2.5
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)]

Probably related to: #2258

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions