Skip to content

Commit

Permalink
Replaced GapNotSorted with ValueError.
Browse files Browse the repository at this point in the history
  • Loading branch information
salt-die committed Nov 27, 2023
1 parent 8f53c7f commit ed2fb2a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/mind_the_gaps/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""A library for unions, intersections, subtractions, and xors of intervals (gaps)."""
from .gaps import Endpoint, Gaps, GapsNotSorted, NegativeInfinity, PositiveInfinity
from .gaps import Endpoint, Gaps, NegativeInfinity, PositiveInfinity
from .var import x

__all__ = [
"Endpoint",
"Gaps",
"GapsNotSorted",
"NegativeInfinity",
"PositiveInfinity",
"x",
Expand Down
16 changes: 7 additions & 9 deletions src/mind_the_gaps/gaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from operator import and_, or_, xor
from typing import Literal, Protocol, Self

__all__ = ["PositiveInfinity", "NegativeInfinity", "Endpoint", "GapsNotSorted", "Gaps"]
__all__ = ["PositiveInfinity", "NegativeInfinity", "Endpoint", "Gaps"]


def sub(a: bool, b: bool) -> bool:
Expand Down Expand Up @@ -157,10 +157,6 @@ def _merge(
return endpoints


class GapsNotSorted(Exception):
...


@dataclass
class Gaps[T: SupportsLessThan]:
"""
Expand All @@ -186,10 +182,12 @@ def __post_init__(self):
for i in range(len(self.endpoints) - 1):
a = self.endpoints[i]
b = self.endpoints[i + 1]
if a.value > b.value or (
a.value == b.value and a.boundary + b.boundary not in {"[]", ")("}
):
raise GapsNotSorted("Intervals overlap or are unsorted.")
if a.value > b.value:
raise ValueError("Intervals unsorted.")
if a.value == b.value and a.boundary + b.boundary in {"(]", ")["}:
raise ValueError(
f"Intervals not minimally expressed. Endpoints {a} and {b} can be removed."
)

@classmethod
def from_string(cls, gaps: str) -> Self:
Expand Down

0 comments on commit ed2fb2a

Please sign in to comment.