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 multi-line hook #6888

Closed
jgosmann opened this issue Jun 7, 2022 · 2 comments · Fixed by #6944
Closed

init-hook no longer supports multi-line hook #6888

jgosmann opened this issue Jun 7, 2022 · 2 comments · Fixed by #6944
Assignees
Labels
Milestone

Comments

@jgosmann
Copy link

jgosmann commented Jun 7, 2022

Bug description

Up to version 2.13.9 multi-line init-hook configurations like the following were supported:

init-hook=
    try: import pylint_venv
    except ImportError: pass
    else: pylint_venv.inithook()

From version 2.14.0 on this no longer works. The error looks like the lines are joined into a single line:

❯ pylint test.py
Traceback (most recent call last):
  File "/Users/jgosmann/Library/Python/3.8/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/Users/jgosmann/Library/Python/3.8/lib/python/site-packages/pylint/__init__.py", line 25, in run_pylint
    PylintRun(argv or sys.argv[1:])
  File "/Users/jgosmann/Library/Python/3.8/lib/python/site-packages/pylint/lint/run.py", line 151, in __init__
    args = _config_initialization(
  File "/Users/jgosmann/Library/Python/3.8/lib/python/site-packages/pylint/config/config_initialization.py", line 48, in _config_initialization
    exec(utils._unquote(config_data["init-hook"]))  # pylint: disable=exec-used
  File "<string>", line 1
    try: import pylint_venvexcept ImportError: passelse: pylint_venv.inithook()
                                  ^
SyntaxError: invalid syntax

Configuration

init-hook=
    try: import pylint_venv
    except ImportError: pass
    else: pylint_venv.inithook()


### Command used

```shell
pylint test.py

Pylint output

Traceback (most recent call last):
  File "/Users/jgosmann/Library/Python/3.8/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/Users/jgosmann/Library/Python/3.8/lib/python/site-packages/pylint/__init__.py", line 25, in run_pylint
    PylintRun(argv or sys.argv[1:])
  File "/Users/jgosmann/Library/Python/3.8/lib/python/site-packages/pylint/lint/run.py", line 151, in __init__
    args = _config_initialization(
  File "/Users/jgosmann/Library/Python/3.8/lib/python/site-packages/pylint/config/config_initialization.py", line 48, in _config_initialization
    exec(utils._unquote(config_data["init-hook"]))  # pylint: disable=exec-used
  File "<string>", line 1
    try: import pylint_venvexcept ImportError: passelse: pylint_venv.inithook()
                                  ^
SyntaxError: invalid syntax

Expected behavior

The init-hook runs without a syntax error.

Pylint version

pylint 2.14.0 (and 2.14.1)
astroid 2.11.5
Python 3.8.13 (default, May 10 2022, 11:26:18)
[Clang 13.0.0 (clang-1300.0.29.3)]

OS / Environment

No response

Additional dependencies

pylint-venv==2.2.0

@jgosmann jgosmann added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jun 7, 2022
@Pierre-Sassoulas Pierre-Sassoulas added Regression and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jun 7, 2022
@cdce8p cdce8p added the Configuration Related to configuration label Jun 7, 2022
@DanielNoord DanielNoord added this to the 2.14.2 milestone Jun 7, 2022
@JonathanCasey
Copy link

I have also run into this in pylint 2.14.1. The workaround I found is to add a semicolon to the end of each line. This seems to allow it to still execute each statement after joining the lines into a single line.

@jgosmann
Copy link
Author

This does not seem to work for try-except.

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.

5 participants