Fix parameter parsing when value contains '=' inside a string (#864)#880
Open
SAY-5 wants to merge 2 commits into
Open
Fix parameter parsing when value contains '=' inside a string (#864)#880SAY-5 wants to merge 2 commits into
SAY-5 wants to merge 2 commits into
Conversation
PythonTranslator.inspect treated any line with more than one '=' as unparseable, which incorrectly rejected parameter lines like s = "a=b" where the second '=' is inside a string literal. Count only top-level assignment operators using tokenize so the existing PARAMETER_PATTERN regex (which already handles '=' in values correctly) is given a chance to match. Closes nteract#864
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #864.
PythonTranslator.inspectcounted=characters naively withline.count("="), so lines likes = "a=b"were flagged as having multiple assignments and skipped with anUnable to parsewarning. The cell ended up exposing nosparameter, and any value passed to it viapapermill -p s ...was then reported asPassed unknown parameter: s.Replaced the naive count with a small helper that tokenizes the line via the
tokenizemodule and counts only top-levelOPtokens with string=.=inside string literals is not anOPtoken, so it is no longer counted. Falls back to the original naive count onTokenError/SyntaxErrorso partial multiline definitions still flow into the existing accumulator path unchanged.The existing
PARAMETER_PATTERNregex already handles values containing=correctly; the fix is purely the pre-filter that was rejecting them too early.Added two parametrize entries to
test_inspect_pythonas regression tests for=in double- and single-quoted string literals. Fullpapermill/tests/test_translators.pysuite (277 tests) passes locally.