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

Function _convert_other

Lib/_pydecimal.py:5994–6011  ·  view source on GitHub ↗

Convert other to Decimal. Verifies that it's ok to use in an implicit construction. If allow_float is true, allow conversion from float; this is used in the comparison methods (__eq__ and friends).

(other, raiseit=False, allow_float=False)

Source from the content-addressed store, hash-verified

5992##### Helper Functions ####################################################
5993
5994def _convert_other(other, raiseit=False, allow_float=False):
5995 """Convert other to Decimal.
5996
5997 Verifies that it's ok to use in an implicit construction.
5998 If allow_float is true, allow conversion from float; this
5999 is used in the comparison methods (__eq__ and friends).
6000
6001 """
6002 if isinstance(other, Decimal):
6003 return other
6004 if isinstance(other, int):
6005 return Decimal(other)
6006 if allow_float and isinstance(other, float):
6007 return Decimal.from_float(other)
6008
6009 if raiseit:
6010 raise TypeError("Unable to convert %s to Decimal" % other)
6011 return NotImplemented
6012
6013def _convert_for_comparison(self, other, equality_op=False):
6014 """Given a Decimal instance self and a Python object other, return

Callers 15

compareMethod · 0.85
__add__Method · 0.85
__sub__Method · 0.85
__rsub__Method · 0.85
__mul__Method · 0.85
__truediv__Method · 0.85
__rtruediv__Method · 0.85
__divmod__Method · 0.85
__rdivmod__Method · 0.85
__mod__Method · 0.85
__rmod__Method · 0.85
remainder_nearMethod · 0.85

Calls 2

DecimalClass · 0.85
from_floatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…