Coverage for src/hypra/_typing.py: 100.00%
11 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-26 22:12 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-26 22:12 +0000
1"""Input types shared by the public symbolic and numerical APIs."""
3from collections.abc import Iterable
4from typing import Literal, cast
6import sympy as s
8type ExactInteger = int | s.Integer
9type IntegerWord = (
10 tuple[ExactInteger, ...] | list[int] | list[s.Integer] | list[ExactInteger] | s.Tuple
11)
12type ExactScalar = s.Expr | int
13type Interval = Literal["0<z<1"]
14type Boundary = Literal["upper", "lower"]
15type RealRegion = Literal["0<x<1", "-1<x<0", "x>1", "x<-1"]
18def as_integer_tuple(word: IntegerWord) -> tuple[int, ...]:
19 """Convert a word whose entries have been validated as exact integers."""
20 # SymPy Tuple stores its entries as Basic, regardless of their actual type.
21 return tuple(map(int, cast(Iterable[ExactInteger], word)))