from .math_basis_points_convert_rate import convert_rate from .math_basis_points_types import RateUnit _MAX_SAFE = 9007199254740991 def from_basis_points(basis_points: int, unit: RateUnit) -> str: """Integer basis points as the shortest exact decimal in another unit.""" if isinstance(basis_points, bool) or not isinstance(basis_points, int): raise TypeError("basisPoints must be an integer, received %r" % (basis_points,)) # Python would go further, but TypeScript cannot, and the three languages # must give the same answer or the same error. if basis_points > _MAX_SAFE or basis_points < -_MAX_SAFE: raise ValueError("basisPoints is outside the safe integer range (±9007199254740991)") return convert_rate(str(basis_points), "basis-points", unit)