Skip to content

[v3] LocalStore.get clarification #1745

@d-v-b

Description

@d-v-b

in v3, the following function gets bytes for the LocalStore.get method:

def _get(path: Path, byte_range: Optional[Tuple[int, Optional[int]]] = None) -> bytes:
    if byte_range is not None:
        start = byte_range[0]
        end = (start + byte_range[1]) if byte_range[1] is not None else None
    else:
        return path.read_bytes()
    with path.open("rb") as f:
        size = f.seek(0, io.SEEK_END)
        if start is not None:
            if start >= 0:
                f.seek(start)
            else:
                f.seek(max(0, size + start))
        if end is not None:
            if end < 0:
                end = size + end
            return f.read(end - f.tell())
        return f.read()

I have a few questions about this function that would help me write tests for it. I think @jhamman @normanrz are the main people I need answers from, but I'd be curious to hear if anyone else has thoughts.

  • the annotation of the function signature is Optional[Tuple[int, Optional[int]]], but the body of the function can handle tuple[None, int]. Should we change annotation of the function signature to tuple[int | None, int | None] | None?
  • I was initially confused about the semantics of byte_range -- I thought it defined an interval as a start and a stop, but now I understand that byte_range defines a start and a step size. This would be more transparent if we used keyword arguments like start and step instead of a tuple. Would switching to keyword arguments be a problem for this API? I think the win in clarity might be worth it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions