From ae5da2d8202b0812c48e182bab18b23804934db8 Mon Sep 17 00:00:00 2001 From: "nikita.smirnov" Date: Wed, 27 Nov 2024 15:17:11 +0400 Subject: [PATCH 1/4] support-equal-char-in-python-translator --- papermill/tests/notebooks/complex_parameters.ipynb | 7 ++++--- papermill/tests/test_inspect.py | 9 +++++++++ papermill/translators.py | 3 --- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/papermill/tests/notebooks/complex_parameters.ipynb b/papermill/tests/notebooks/complex_parameters.ipynb index 1c7284f0..171dec26 100644 --- a/papermill/tests/notebooks/complex_parameters.ipynb +++ b/papermill/tests/notebooks/complex_parameters.ipynb @@ -21,9 +21,10 @@ "# Interesting c variable\n", "c: \"NoneType\" = None\n", "# Not introspectable line\n", - "d = a == 3\n", - "# Broken name definition\n", - "= 2" + "d = \"a = 3\" # str value with '=' character\n", + "e = (a != 3 and 2 <= a <= 3) or a == 1 # bool value with logical operators\n", + "= 2\n", + "# Broken name definition\n" ] } ], diff --git a/papermill/tests/test_inspect.py b/papermill/tests/test_inspect.py index 3b1cca7f..44a32aeb 100644 --- a/papermill/tests/test_inspect.py +++ b/papermill/tests/test_inspect.py @@ -45,6 +45,13 @@ def click_context(): "help": "Nice list", }, "c": {"name": "c", "inferred_type_name": "NoneType", "default": "None", "help": ""}, + "d": {"name": "d", "inferred_type_name": "None", "default": "\"a = 3\"", "help": "str value with '=' character"}, + "e": { + "name": "e", + "inferred_type_name": "None", + "default": "(a != 3 and 2 <= a <= 3) or a == 1", + "help": "bool value with logical operators" + }, }, ), (_get_fullpath("notimplemented_translator.ipynb"), {}), @@ -87,6 +94,8 @@ def test_str_path(): " a: float (default 2.25) Variable a", " b: List[str] (default ['Hello','World'])\n Nice list", " c: NoneType (default None) ", + " d: Unknown type (default \"a = 3\")\n str value with '=' character", + " e: Unknown type (default (a != 3 and 2 <= a <= 3) or a == 1)\n bool value with logical operators", ], ), ( diff --git a/papermill/translators.py b/papermill/translators.py index 1cb43d89..3b5c0ace 100644 --- a/papermill/translators.py +++ b/papermill/translators.py @@ -246,9 +246,6 @@ def flatten_accumulator(accumulator): if nequal > 0: grouped_variable.append(flatten_accumulator(accumulator)) accumulator = [] - if nequal > 1: - logger.warning(f"Unable to parse line {iline + 1} '{line}'.") - continue accumulator.append(line) grouped_variable.append(flatten_accumulator(accumulator)) From 86d4eaa17947812aae2d87d47a6e69916a3364f5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 27 Nov 2024 12:42:54 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- papermill/tests/test_inspect.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/papermill/tests/test_inspect.py b/papermill/tests/test_inspect.py index 44a32aeb..08598428 100644 --- a/papermill/tests/test_inspect.py +++ b/papermill/tests/test_inspect.py @@ -45,12 +45,17 @@ def click_context(): "help": "Nice list", }, "c": {"name": "c", "inferred_type_name": "NoneType", "default": "None", "help": ""}, - "d": {"name": "d", "inferred_type_name": "None", "default": "\"a = 3\"", "help": "str value with '=' character"}, + "d": { + "name": "d", + "inferred_type_name": "None", + "default": "\"a = 3\"", + "help": "str value with '=' character", + }, "e": { "name": "e", "inferred_type_name": "None", "default": "(a != 3 and 2 <= a <= 3) or a == 1", - "help": "bool value with logical operators" + "help": "bool value with logical operators", }, }, ), From eacd06ec58c5dc073d4cb23c11570467f33c1f39 Mon Sep 17 00:00:00 2001 From: "nikita.smirnov" Date: Wed, 27 Nov 2024 17:15:24 +0400 Subject: [PATCH 3/4] Corrected test set --- .../tests/notebooks/complex_parameters.ipynb | 7 +++++-- papermill/tests/test_inspect.py | 15 +++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/papermill/tests/notebooks/complex_parameters.ipynb b/papermill/tests/notebooks/complex_parameters.ipynb index 171dec26..b33db466 100644 --- a/papermill/tests/notebooks/complex_parameters.ipynb +++ b/papermill/tests/notebooks/complex_parameters.ipynb @@ -21,8 +21,11 @@ "# Interesting c variable\n", "c: \"NoneType\" = None\n", "# Not introspectable line\n", - "d = \"a = 3\" # str value with '=' character\n", - "e = (a != 3 and 2 <= a <= 3) or a == 1 # bool value with logical operators\n", + "d = \"a = 3\"\n", + "# str value with equal character\n", + "e = 1 # comment with '=' character\n", + "f = (a != 3 and 2 <= a <= 3) or a == 1\n", + "# bool value with logical operators\n", "= 2\n", "# Broken name definition\n" ] diff --git a/papermill/tests/test_inspect.py b/papermill/tests/test_inspect.py index 08598428..43340e83 100644 --- a/papermill/tests/test_inspect.py +++ b/papermill/tests/test_inspect.py @@ -49,13 +49,15 @@ def click_context(): "name": "d", "inferred_type_name": "None", "default": "\"a = 3\"", - "help": "str value with '=' character", + "help": "" }, - "e": { - "name": "e", + "e": {"name": "e", "inferred_type_name": "None", "default": "1", "help": "comment with '=' character", + }, + "f": { + "name": "f", "inferred_type_name": "None", "default": "(a != 3 and 2 <= a <= 3) or a == 1", - "help": "bool value with logical operators", + "help": "", }, }, ), @@ -99,8 +101,9 @@ def test_str_path(): " a: float (default 2.25) Variable a", " b: List[str] (default ['Hello','World'])\n Nice list", " c: NoneType (default None) ", - " d: Unknown type (default \"a = 3\")\n str value with '=' character", - " e: Unknown type (default (a != 3 and 2 <= a <= 3) or a == 1)\n bool value with logical operators", + " d: Unknown type (default \"a = 3\")", + " e: Unknown type (default 1) comment with '=' character", + " f: Unknown type (default (a != 3 and 2 <= a <= 3) or a == 1)", ], ), ( From c97158768968a2f139101d118cc2887c14fb6dac Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 27 Nov 2024 13:17:35 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- papermill/tests/test_inspect.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/papermill/tests/test_inspect.py b/papermill/tests/test_inspect.py index 43340e83..40a5a269 100644 --- a/papermill/tests/test_inspect.py +++ b/papermill/tests/test_inspect.py @@ -45,13 +45,12 @@ def click_context(): "help": "Nice list", }, "c": {"name": "c", "inferred_type_name": "NoneType", "default": "None", "help": ""}, - "d": { - "name": "d", + "d": {"name": "d", "inferred_type_name": "None", "default": "\"a = 3\"", "help": ""}, + "e": { + "name": "e", "inferred_type_name": "None", - "default": "\"a = 3\"", - "help": "" - }, - "e": {"name": "e", "inferred_type_name": "None", "default": "1", "help": "comment with '=' character", + "default": "1", + "help": "comment with '=' character", }, "f": { "name": "f",