From 18c3d3da4c0db20e799c8e6dee16f3c26b40efd3 Mon Sep 17 00:00:00 2001 From: Aman Sachan Date: Mon, 11 May 2026 01:48:10 +0000 Subject: [PATCH] fix: parse parameter strings containing '=' in papermill/translators.py Change the threshold for skipping lines with multiple equals signs from nequal > 1 to nequal > 2. Lines like s = 'a=b' have 2 equals signs (one assignment, one inside the string), but were incorrectly skipped as unparseable multi-assignments. Fixes issue #864: Parameter strings cannot contain '=' - Before: s = 'a=b' was skipped (nequal=2, threshold was >1) - After: s = 'a=b' is correctly parsed (nequal=2, threshold is now >2) - Multi-assignment lines like a = b = 1 (nequal=3) are still skipped Also adds a test case for parameter strings with embedded equals. --- papermill/tests/test_translators.py | 4 ++++ papermill/translators.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/papermill/tests/test_translators.py b/papermill/tests/test_translators.py index 0edc1f07..4d49a2ca 100644 --- a/papermill/tests/test_translators.py +++ b/papermill/tests/test_translators.py @@ -107,6 +107,10 @@ def test_translate_comment_python(test_input, expected): Parameter("b", "float", "-2.3432", "My b variable"), ], ), + ( + 's = "a=b"', + [Parameter("s", "None", '"a=b"', "")], + ), ], ) def test_inspect_python(test_input, expected): diff --git a/papermill/translators.py b/papermill/translators.py index 1cb43d89..47a62e81 100644 --- a/papermill/translators.py +++ b/papermill/translators.py @@ -246,7 +246,7 @@ def flatten_accumulator(accumulator): if nequal > 0: grouped_variable.append(flatten_accumulator(accumulator)) accumulator = [] - if nequal > 1: + if nequal > 2: logger.warning(f"Unable to parse line {iline + 1} '{line}'.") continue