Repository navigation
Select: preserve context (incl. _params) when building subcons - #1194
Open
DresdenGman wants to merge 1 commit into
Open
DresdenGman wants to merge 1 commit into
DresdenGman wants to merge 1 commit into
Conversation
Select._build used to call sc.build(obj, **context), which flattened the context into build keywords and reset _params, breaking this._params lookups in constructs nested inside Select (issue construct#1038). Build each subcon into a temporary stream with a copy of the current context instead, mirroring how _parse tries each subcon in place.
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 #1038.
When building,
Select._buildcalledsc.build(obj, **context), which flattens the context into build keywords — andbuild_streamthen setscontext._paramsto that flattened dict. Constructs nested insideSelectthat look upthis._params(for exampleIfThenElse(this._params.ctx == 1, Byte, Short)) therefore saw the wrong parameters when building: silently taking the wrong branch with a lambda condition, or raisingSelectErrorwith athis._paramscondition. Parsing was never affected, because_parsepasses the context through unchanged.Following the approach of trying each subcon in place, as
_parsedoes: build each subcon into a temporary stream with a copy of the current context (Container(context)), so_paramsand everything else survive intact, and context changes made by a failed attempt cannot leak into the next attempt or back into the caller.Tests: the existing xfail test for this issue (
test_select_issue_1038) now passes and its xfail marker is removed, with added assertions for thectx=2branch and for the parse direction. Two further tests cover isolation between failed attempts and visibility of sibling fields built before theSelect. Full suite: 474 passed, 13 xfailed, against a baseline of 471 passed, 14 xfailed — no new failures.