Allow assign_field() to descend into a simple (non-repeating) field (#55)#86
Closed
CedricConday wants to merge 1 commit into
Closed
Conversation
…ohnpaulett#55) A field parsed as a single value is stored as a bare string, so assign_field() addressing a repetition/component/subcomponent of it hit 'TypeError: str object does not support item assignment' when it tried to slice-assign into that string. Promote a bare string to a Repetition (and likewise a single-component repetition to a Component) before descending, preserving the existing value. Addresses item 1 of johnpaulett#55.
adf6ed2 to
4f280eb
Compare
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.
Addresses item 1 of #55
Cause
A field parsed as a single value is stored as a bare
str(e.g. field 3 isField(['field'])), whereas a repeating field holdsRepetitionobjects. Whenassign_field()addresses a repetition (or component/subcomponent) of a simple field,field(repeat_num)returns that bare string and the subsequentrepetition[:] = [value]slice-assignment raises.Fix
Before descending, promote a bare string to a
Repetition(and, one level down, a single-component repetition to aComponent), preserving the existing value — which is the behaviour the issue asks for. Assigning the whole field/repetition still replaces it as before.Tests
Added
test_assign_deeper_into_simple_fieldcovering the reported repetition case plus the component and subcomponent levels:assign_field('NewRep', 3, 1)→ field 3 =NewRepassign_field('X', 3, 1, 2)→ field 3 =field^Xassign_field('Y', 4, 1, 1, 2)→ field 4 =rep1&Y~rep2These fail on
main(TypeError) and pass with the fix. Full suite stays green (101 tests); the existingtest_assign(assignment into empty fields) is unaffected.