pytoolz / pytoolz/toolz

get_in function: add example of giving a string to the keys argument

Open
#548 2 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.