nested.get_by_path fails with default
@thequilo Do you remember, why the default is only considered for KeyError and IndexError?
When should get_by_path fail?
https://github.com/fgnt/paderbox/blob/67279558c193ee6880e94a2e9022733350910879/paderbox/utils/nested.py#L476-L493
Here, an extension of the doctest. IMHO the last example should work.
>>> d = {'a': 'b', 'c': {'d': {'e': 'f'}, 'g': [1, [2, 3], 4]}}
...
>>> get_by_path(d, 'c.b.c', default=42)
42
>>> get_by_path(d, 'a.b.c', default=42)
Traceback (most recent call last):
...
TypeError: string indices must be integers
The leafs in a nested structure can have any type and hence any Exception could be thrown. So I don't get, why there is an if statement.
I had a reason for this, but I don't remember. I think I did this because the default value can conflict with the allow_early_stopping option, where it is not clear whether the default value or the value at the partial path should be returned when an exception is encountered. While writing I thought that the default should only be returned when a value is missing (i.e., KeyError for dict and IndexError for list/tuple). But I agree that your example should work
What behavior would you expect when get_by_path(d, 'a.b.c', default=42, allow_early_stopping=True)?
Now, where you mention this, I would say the call should fail. Early stopping and default should be alternative arguments. Wenn you provide both, I have no idea, what the function should do.