Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MarKett opened this issue Jun 18, 2019 · 1 comment
Open
Labels
Bug 🪲 Import system Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine

Comments

@MarKett
Copy link

MarKett commented Jun 18, 2019

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

@PCManticore
Copy link
Contributor

Thanks @MarKett for creating the issue. This is the second one recently, we definitely need to fix this behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Import system Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine
Projects
None yet
Development

No branches or pull requests

3 participants