MCPcopy Index your code
hub / github.com/python/cpython / _convert

Function _convert

Lib/statistics.py:1623–1640  ·  view source on GitHub ↗

Convert value to given numeric type T.

(value, T)

Source from the content-addressed store, hash-verified

1621
1622
1623def _convert(value, T):
1624 """Convert value to given numeric type T."""
1625 if type(value) is T:
1626 # This covers the cases where T is Fraction, or where value is
1627 # a NAN or INF (Decimal or float).
1628 return value
1629
1630 if issubclass(T, int) and value.denominator != 1:
1631 T = float
1632
1633 try:
1634 # FIXME: what do we do if this overflows?
1635 return T(value)
1636 except TypeError:
1637 if issubclass(T, Decimal):
1638 return T(value.numerator) / T(value.denominator)
1639 else:
1640 raise
1641
1642
1643def _fail_neg(values, errmsg='negative value'):

Callers 4

meanFunction · 0.85
harmonic_meanFunction · 0.85
varianceFunction · 0.85
pvarianceFunction · 0.85

Calls 1

TFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…