Skip to content

[FEATURE] get_deep() method #14

Open
@Marco-Sulla

Description

@Marco-Sulla

get_deep(*args, default=_sentinel) can accept a single argument, that must be an iterable, or multiple arguments.

The first element must be a key of the frozendict. If there's no a second element, the value is returned. If it's present, it tries to use it as argument for the eventual __getitem__() of the value object, and so on.

In this process, if a KeyError, an IndexError or a TypeError is raised, if default is set its value is returned, otherwise the exception will be re-raised.

Example:

fd = frozendict({1: [42]})
fd.get_deep(1, 0)
# 42
fd.get_deep(range(3), default=1981)
# 1981
fd.get_deep((1, 1))
# IndexError: list index out of range

See also #13

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Effort: MediumHow to waste a beautiful weekendNeeds: DocImprovements or additions to documentationNeeds: TestHey, it compiles! Ship it!Priority: LowNot a big problem...Type: EnhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions