Skip to content

errors

Custom exception raised by RangedHeap.

ChoiceNotFoundError #

Bases: RangedHeapBaseError

Raised when attempting to delete a choice that doesn't exist in the specified value range.

Source code in ranged_heap/errors.py
30
31
32
33
34
35
36
class ChoiceNotFoundError(RangedHeapBaseError):
    """Raised when attempting to delete a choice that doesn't exist in the specified value range."""

    default_message: str = "Choice {key} not found in value {value}."

    def __init__(self, key: str, value: int, message: Optional[str] = None):
        super().__init__(message, key=key, value=value)

EmptyHeapError #

Bases: RangedHeapBaseError

Raised when trying to pop or get the best choice from an empty heap.

Source code in ranged_heap/errors.py
24
25
26
27
class EmptyHeapError(RangedHeapBaseError):
    """Raised when trying to pop or get the best choice from an empty heap."""

    default_message: str = "The Ranged Heap is empty!"

InvalidChoiceError #

Bases: RangedHeapBaseError

Raised when attempting to add or adjust a choice with an invalid value (out of range).

Source code in ranged_heap/errors.py
39
40
41
42
43
44
45
class InvalidChoiceError(RangedHeapBaseError):
    """Raised when attempting to add or adjust a choice with an invalid value (out of range)."""

    default_message: str = "Value {value} is out of range."

    def __init__(self, value: int, message: Optional[str] = None):
        super().__init__(message, value=value)

InvalidRangeError #

Bases: RangedHeapBaseError

Raised when the range k is less than 0.

Source code in ranged_heap/errors.py
18
19
20
21
class InvalidRangeError(RangedHeapBaseError):
    """Raised when the range k is less than 0."""

    default_message: str = "k must be greater or equal to 0."

RangedHeapBaseError #

Bases: ABC, Exception

Base class for other exceptions with default error message.

Source code in ranged_heap/errors.py
 7
 8
 9
10
11
12
13
14
15
class RangedHeapBaseError(abc.ABC, Exception):
    """Base class for other exceptions with default error message."""

    default_message: str = "An error occurred."

    def __init__(self, message: Optional[str] = None, **kwargs):
        if message is None:
            message = self.default_message.format(**kwargs)
        super().__init__(message)