Add support for tuples in get_attr #3302
Open
+17
−4
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.
The get_attr function is intended to be able to support an input with a path such as
[0]
and a value of['foo']
and parse out the fist index of the value to getfoo
as the result.Without the change in this PR, the such an input will not match the indexing regex, and instead it will reach the else statement and reach the code intended to access dictionary indexes. This will fail with a type error, so this PR updates the regex to properly reach the part of the code that handles indexes without a word string before them.
That code still fails for the same input; it assumes that it is getting the index of a list from a dictionary, so it attempts to call
.get()
on the base input. This will not work if the input value is not a dictionary, so we need to add the conditional to only call.get()
if there is a string before the first open bracket in the part of the path that we are parsing.Finally, this code can't be reached currently with a list due to how we memoize input parameters to endpoints; all parameter types have to be hash-able. While this function could theoretically get called with a list as input from another context, this is a private interface and it is only internally called from the endpoint provider. Because of this, I've updated the docblock to specify
tuple
as the input type instead oflist
.