Pylint should never execute code within repo under analysis (as this could affect the analysis, or potentially even do something malicious)
Actual behaviour:
When Pylint is run in root of a repo, modules in the repo will sometimes be loaded instead of Pylint's own imports! This usually causes Pylint to crash (but could potentially do anything).
Example:
Root of project 39565135 contains a file called appdirs.py. When a Pylint dependency tries to import the appdir package, it mistakenly imports the local appdirs.py file instead.
INFO:root:../input/39565135
ERROR:root:['Traceback (most recent call last):', ' File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main', ' "__main__", mod_spec)', ' File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code', ' exec(code, run_globals)', ' File "/app/clean_env_py3/lib/python3.6/site-packages/pylint/__main__.py", line 7, in <module>', ' pylint.run_pylint()', ' File "/app/clean_env_py3/lib/python3.6/site-packages/pylint/__init__.py", line 23, in run_pylint', ' PylintRun(sys.argv[1:])', ' File "/app/clean_env_py3/lib/python3.6/site-packages/pylint/lint.py", line 1637, in __init__', ' linter.load_default_plugins()', ' File "/app/clean_env_py3/lib/python3.6/site-packages/pylint/lint.py", line 645, in load_default_plugins', ' checkers.initialize(self)', ' File "/app/clean_env_py3/lib/python3.6/site-packages/pylint/checkers/__init__.py", line 61, in initialize', ' register_plugins(linter, __path__[0])', ' File "/app/clean_env_py3/lib/python3.6/site-packages/pylint/utils/utils.py", line 218, in register_plugins', ' module = modutils.load_module_from_file(join(directory, filename))', ' File "/app/clean_env_py3/lib/python3.6/site-packages/astroid/modutils.py", line 280, in load_module_from_file', ' return load_module_from_modpath(modpath, path, use_sys)', ' File "/app/clean_env_py3/lib/python3.6/site-packages/astroid/modutils.py", line 241, in load_module_from_modpath', ' module = imp.load_module(curname, mp_file, mp_filename, mp_desc)', ' File "/usr/local/lib/python3.6/imp.py", line 235, in load_module', ' return load_source(name, filename, file)', ' File "/usr/local/lib/python3.6/imp.py", line 172, in load_source', ' module = _load(spec)', ' File "<frozen importlib._bootstrap>", line 684, in _load', ' File "<frozen importlib._bootstrap>", line 665, in _load_unlocked', ' File "<frozen importlib._bootstrap_external>", line 678, in exec_module', ' File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed', ' File "/app/clean_env_py3/lib/python3.6/site-packages/pylint/checkers/imports.py", line 40, in <module>', ' import isort', ' File "/app/clean_env_py3/lib/python3.6/site-packages/isort/__init__.py", line 25, in <module>', ' from . import settings # noqa: F401', ' File "/app/clean_env_py3/lib/python3.6/site-packages/isort/settings.py", line 52, in <module>', " if appdirs.system == 'darwin':", "AttributeError: module 'appdirs' has no attribute 'system'"]
As appdirs package is not installed, the code is meant to catch an ImportError. Instead, it loads the local appdirs.py, which results in AttributeError: module 'appdirs' has no attribute 'system'" as it is a different module to what it expected.
Expected Behaviour:
Actual behaviour:
Example:
39565135
contains a file calledappdirs.py
. When a Pylint dependency tries to import theappdir
package, it mistakenly imports the localappdirs.py
file instead.Details:
https://github.com/PyCQA/pylint/blob/pylint-2.4.4/pylint/checkers/imports.py#L40
https://github.com/timothycrosley/isort/blob/4.3.21/isort/settings.py#L45
As
appdirs
package is not installed, the code is meant to catch anImportError
. Instead, it loads the localappdirs.py
, which results inAttributeError: module 'appdirs' has no attribute 'system'"
as it is a different module to what it expected.