From b379ef3acc2a983140994c93a2ea2c99e260c9c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Thu, 23 Jun 2022 15:12:06 +0200 Subject: [PATCH] Fix handling of quoted ``init-hook`` (#7010) Co-authored-by: Jacob Walls --- doc/whatsnew/2/2.14/full.rst | 3 +++ pylint/config/config_initialization.py | 2 +- .../functional/ini/pylintrc_with_quoted_init_hook.0.out | 1 + .../config/functional/ini/pylintrc_with_quoted_init_hook.ini | 4 ++++ 4 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 tests/config/functional/ini/pylintrc_with_quoted_init_hook.0.out create mode 100644 tests/config/functional/ini/pylintrc_with_quoted_init_hook.ini diff --git a/doc/whatsnew/2/2.14/full.rst b/doc/whatsnew/2/2.14/full.rst index 02feecd437..d306a7f825 100644 --- a/doc/whatsnew/2/2.14/full.rst +++ b/doc/whatsnew/2/2.14/full.rst @@ -9,6 +9,9 @@ Release date: TBA Closes #6950 +* Fixed regression that didn't allow quoted ``init-hooks`` in option files. + + Closes #7006 What's New in Pylint 2.14.3? ---------------------------- diff --git a/pylint/config/config_initialization.py b/pylint/config/config_initialization.py index 4e064d1e86..8d2de1df7a 100644 --- a/pylint/config/config_initialization.py +++ b/pylint/config/config_initialization.py @@ -45,7 +45,7 @@ def _config_initialization( # Run init hook, if present, before loading plugins if "init-hook" in config_data: - exec(config_data["init-hook"]) # pylint: disable=exec-used + exec(utils._unquote(config_data["init-hook"])) # pylint: disable=exec-used # Load plugins if specified in the config file if "load-plugins" in config_data: diff --git a/tests/config/functional/ini/pylintrc_with_quoted_init_hook.0.out b/tests/config/functional/ini/pylintrc_with_quoted_init_hook.0.out new file mode 100644 index 0000000000..21edc7ba0f --- /dev/null +++ b/tests/config/functional/ini/pylintrc_with_quoted_init_hook.0.out @@ -0,0 +1 @@ +I should just print diff --git a/tests/config/functional/ini/pylintrc_with_quoted_init_hook.ini b/tests/config/functional/ini/pylintrc_with_quoted_init_hook.ini new file mode 100644 index 0000000000..8b10877edf --- /dev/null +++ b/tests/config/functional/ini/pylintrc_with_quoted_init_hook.ini @@ -0,0 +1,4 @@ +# Check that we support quoted init-hooks +# See https://github.com/PyCQA/pylint/issues/7006 +[MAIN] +init-hook='print("I should just print")'