(value, local_type_id: int)
| 212 | |
| 213 | |
| 214 | def _int_value(value, local_type_id: int) -> int: |
| 215 | min_value, max_value = _INT_RANGES_BY_TYPE_ID[local_type_id] |
| 216 | if isinstance(value, decimal.Decimal): |
| 217 | value = _canonical_decimal(value) |
| 218 | if not value.is_finite() or value != value.to_integral_exact(): |
| 219 | raise ValueError("decimal is not an integral value") |
| 220 | result = int(value) |
| 221 | elif type(value) is float: |
| 222 | if not math.isfinite(value) or not value.is_integer(): |
| 223 | raise ValueError("floating value is not a finite integer") |
| 224 | result = int(value) |
| 225 | elif type(value) is int: |
| 226 | result = value |
| 227 | else: |
| 228 | raise ValueError(f"expected numeric value, got {type(value)!r}") |
| 229 | if result < min_value or result > max_value: |
| 230 | raise OverflowError(f"value {result} is outside target integer range") |
| 231 | return result |
| 232 | |
| 233 | |
| 234 | def _float_value(value, local_type_id: int) -> float: |
no test coverage detected