MCPcopy Create free account
hub / github.com/apache/fory / _int_value

Function _int_value

python/pyfory/converter.py:214–231  ·  view source on GitHub ↗
(value, local_type_id: int)

Source from the content-addressed store, hash-verified

212
213
214def _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
234def _float_value(value, local_type_id: int) -> float:

Callers 1

_numeric_valueFunction · 0.85

Calls 2

_canonical_decimalFunction · 0.85
is_finiteMethod · 0.45

Tested by

no test coverage detected