Module digint.tools

tools

Holds common tool functions and classes used in the dint module.

Functions

def absindex(index: int, reference_length: Union[Sized, int]) ‑> int

absindex()

Takes the given index and the legnth contex its used in and returns a absolute index that wraps a negative index into a positive one while throwing relevant errors for out of bounds indexes.

Arguments

index – The index in question. reference_length – The length of the object being sliced, or the Sized object itself.

Raises

ValueError
Raised when an erroneous length is given.
IndexError
Raised when the given index is / would be out of bounds.

Returns

The absolute index (will never be negative).

def iter_to_slices(i: Iterable[int], reference_length: Union[Sized, int]) ‑> Tuple[slice, ...]

iter_to_slices()

Converts an iterable of integers into a series of slices with a step value of 1.

Arguments

i – The iterable to be converted. reference_length – The length of the object being sliced, or the Sized object itself.

Returns

A tuple of slices, each with a step of 1.

def slice_to_range(sl: slice, reference_length: Union[Sized, int]) ‑> range

slice_to_range()

Used to convert a slice object into a range object.

Arguments

sl – The source slice to convert. reference_length – The length of the object being sliced, or the Sized object itself.

Returns

The generated range from the slice.