get_in function: add example of giving a string to the keys argument
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.2k
- Forks
- 280
- Avg merge
- 6d 17h
- Merged PRs (30d)
- 4
Description
It is currently tempting to test get_in like this:
get_in('x', {'x':5}) # returns 5
and conclude that this will also work:
get_in('test', {'test':5}) # actually returns None
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:
juxt(*map(curry(get_in), ['str1', ['str2', 'str3'], 'etc']))
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Search the documentation for the get_in function and read its current argument description and examples first. Add an explicit example showing that a string keys argument is treated as a sequence of keys, including the nested xy case, and make clear what behavior users should expect. Done means the documentation removes the ambiguity without changing implementation behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100