You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It does not work, because 'test' is treated as ['t','e','s','t']. In complex dictionaries, you may actually get a value, like
get_in('xy', {'x': {'y': 5}} ) # returns 5
The documentation should probably call this out explicitly, if this is the intended behavior, perhaps by giving the 'xy' example above.
I, for one, wouldn't mind an implementation where get_in('test', {'test':5}) returns 5, but I wouldn't go so far as to say that is the right approach. I'm imagining it would facilitate doing something like this:
You need to use get_in(['test'], {'test':5}). The first argument is treated as a sequence of keys. Every example in the docstring uses a list as the first argument. get_in('xy', {'x': {'y': 5}} ) happens to work because strings are sequences in Python and is equivalent to get_in(['x', 'y'], {'x': {'y':5}}) (which is the suggested/encouraged form).
I am aware of the behavior, having explicitly explained it in my issue. I am saying that the documentation should not require the reader to infer the dev's intent by reading between the lines of their examples.
If the list form is suggested/encouraged, say so in the documentation.
It is currently tempting to test
get_in
like this:and conclude that this will also work:
It does not work, because
'test'
is treated as['t','e','s','t']
. In complex dictionaries, you may actually get a value, likeThe documentation should probably call this out explicitly, if this is the intended behavior, perhaps by giving the 'xy' example above.
I, for one, wouldn't mind an implementation where
get_in('test', {'test':5})
returns 5, but I wouldn't go so far as to say that is the right approach. I'm imagining it would facilitate doing something like this:The text was updated successfully, but these errors were encountered: