dgilland / pydash

The kitchen sink of Python utility libraries for doing "stuff" in a functional way. Based on the Lo-Dash Javascript library.
http://pydash.readthedocs.io
MIT License
1.28k stars 89 forks source link

Fix path behaviour for set_ #214

Closed DeviousStoat closed 5 months ago

DeviousStoat commented 5 months ago

fixes #213

The default type when setting a missing key is usually given by the PathToken built in to_path_tokens. However this function is incomplete and only builds a list of PathTokens if the path is a string.

The issue here is that that line sets the default type to list if the object to update is not a dict. And as stated above, when we have a path as a list to_path_tokens just returns the list and we don't have any information about the default factory, we just default to list. So when we create the first list and try to update it we expect an index.

This PR updates the to_path_tokens function to be more general and build the list of PathToken even for a list.

The added pragma: no cover are there because this case should now be impossible to reach, the only case where the tokens are not PathTokens is when the path is only 1 non string value and we go directly to the end case as the for loop only iterates on the initial values.

coveralls commented 5 months ago

Coverage Status

coverage: 100.0%. remained the same when pulling c548717bb54b57464612162f143271ed6a6f0f66 on DeviousStoat:fix-set_ into 2a2fb8e58873de6f75a08927aaad653ebfa1fb97 on dgilland:develop.

DeviousStoat commented 5 months ago

Lint fails in CI on files I didn't touch and everything passes localy. Not sure what's going on. Maybe we can just try rerunning it?

dgilland commented 5 months ago

Lint fails in CI on files I didn't touch and everything passes localy. Not sure what's going on. Maybe we can just try rerunning it?

Latest version of black made some changes to the formatting and required some flake8 ignores on certain rules. Rebase with develop to get those changes and lint should be good.