Repository: yt-dlp/yt-dlp
File: yt_dlp/utils.py (Python)

Code before:
    def apply_path(start_obj, path):
        objs = (start_obj,)
        has_branched = False

        for key in variadic(path):
            if is_user_input and key == ':':
                key = ...

            if not casesense and isinstance(key, str):
                key = key.casefold()

            if key is ... or isinstance(key, (list, tuple)) or callable(key):
                has_branched = True

            key_func = functools.partial(apply_key, key)
            objs = itertools.chain.from_iterable(map(key_func, objs))

        return has_branched, objs

    def _traverse_obj(obj, path, last=True):
        has_branched, results = apply_path(obj, path)
        results = LazyList(x for x in map(type_test, results) if x is not None)
        if not results:
            return [] if has_branched and last and default is NO_DEFAULT else None

        return results.exhaust() if get_all and has_branched else results[0]

    for index, path in enumerate(paths, 1):
        result = _traverse_obj(obj, path, index == len(paths))
        if result is not None:
            return result

    return None if default is NO_DEFAULT else default


def traverse_dict(dictn, keys, casesense=True):
    deprecation_warning(f'"{__name__}.traverse_dict" is deprecated and may be removed '
                        f'in a future version. Use "{__name__}.traverse_obj" instead')
    return traverse_obj(dictn, keys, casesense=casesense, is_user_input=True, traverse_string=True)


def get_first(obj, keys, **kwargs):
    return traverse_obj(obj, (..., *variadic(keys)), **kwargs, get_all=False)


def time_seconds(**kwargs):
    t = datetime.datetime.now(datetime.timezone(datetime.timedelta(**kwargs)))
    return t.timestamp()


# create a JSON Web Signature (jws) with HS256 algorithm

Review comment (suggestion):
This is clearer imo:
```py
        if get_all and has_branched:
            if results or (last and default is NO_DEFAULT):
                return results.exhaust()
        elif results:
            return results[0]
```

Code after:
    def apply_path(start_obj, path):
        objs = (start_obj,)
        has_branched = False

        for key in variadic(path):
            if is_user_input and key == ':':
                key = ...

            if not casesense and isinstance(key, str):
                key = key.casefold()

            if key is ... or isinstance(key, (list, tuple)) or callable(key):
                has_branched = True

            key_func = functools.partial(apply_key, key)
            objs = itertools.chain.from_iterable(map(key_func, objs))

        return has_branched, objs

    def _traverse_obj(obj, path, use_list=True):
        has_branched, results = apply_path(obj, path)
        results = LazyList(x for x in map(type_test, results) if x is not None)

        if get_all and has_branched:
            return results.exhaust() if results or use_list else None

        return results[0] if results else None

    for index, path in enumerate(paths, 1):
        use_list = default is NO_DEFAULT and index == len(paths)
        result = _traverse_obj(obj, path, use_list)
        if result is not None:
            return result

    return None if default is NO_DEFAULT else default


def traverse_dict(dictn, keys, casesense=True):
    deprecation_warning(f'"{__name__}.traverse_dict" is deprecated and may be removed '
                        f'in a future version. Use "{__name__}.traverse_obj" instead')
    return traverse_obj(dictn, keys, casesense=casesense, is_user_input=True, traverse_string=True)


def get_first(obj, keys, **kwargs):
    return traverse_obj(obj, (..., *variadic(keys)), **kwargs, get_all=False)


def time_seconds(**kwargs):
    t = datetime.datetime.now(datetime.timezone(datetime.timedelta(**kwargs)))
    return t.timestamp()