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

init-hook no longer supports quoted code #7006

Closed
mathiasritter opened this issue Jun 22, 2022 · 1 comment · Fixed by #7010
Closed

init-hook no longer supports quoted code #7006

mathiasritter opened this issue Jun 22, 2022 · 1 comment · Fixed by #7010
Assignees
Labels
Milestone

Comments

@mathiasritter
Copy link

Bug Report

Since pylint version 2.14.2, the init-hook no longer supports quoted code. This is because with PR #6944, the function call to utils._unquote in pylint/config/config_initialization.py was removed: https://github.com/PyCQA/pylint/pull/6944/files#diff-dd2760aa48f0278b8c66e126913d22c0f9749cca892ef3c4104b957f4c899f68L48-R48

Example

To reproduce this bug, I created a small example repository with the following contents:

src/
    mypackage/
        file1.py
        file2.py
.pylintrc

The contents of file1.py are:

from mypackage.file2 import its_true

The contents of file2.py are:

its_true = True

The contents of .pylintrc are:

[MASTER]
init-hook='import sys; sys.path.append("src")'  # Note that code is quoted
disable=missing-module-docstring,unused-import

The purpose of the init-hook is to add the src directory to the python path, so pylint can locate all imports correctly.

Current Behaviour

When invoking pylint in the repository root with src/mypackage/file1.py, it is unable to import mypackage.file2:

❯ pylint src/mypackage/file1.py
************* Module file1
src/mypackage/file1.py:1:0: E0401: Unable to import 'mypackage.file2' (import-error)

However, pylint is able to import mypackage.file2 if I either

  • unquote the init-hook code or
  • downgrade pylint to version <= 2.14.1

Expected Behaviour

When running pylint src/mypackage/file1.py, pylint should be able to import mypackage.file2.

Environment Information

pylint version 2.14.2
python version 3.10.5
macOS version 12.3.1

@Pierre-Sassoulas
Copy link
Member

Thank you for opening the issue ! Thanks to your analysis we're suddenly figuring out the root cause of some issues that were opened for some time now 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants