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

Function convert

Modules/_decimal/tests/deccheck.py:675–756  ·  view source on GitHub ↗

t is the testset. At this stage the testset contains a tuple of operands t.op of various types. For decimal methods the first operand (self) is always converted to Decimal. If 'convstr' is true, string operands are converted as well. Context operands are of type dec

(t, convstr=True)

Source from the content-addressed store, hash-verified

673 return False
674
675def convert(t, convstr=True):
676 """ t is the testset. At this stage the testset contains a tuple of
677 operands t.op of various types. For decimal methods the first
678 operand (self) is always converted to Decimal. If 'convstr' is
679 true, string operands are converted as well.
680
681 Context operands are of type deccheck.Context, rounding mode
682 operands are given as a tuple (C.rounding, P.rounding).
683
684 Other types (float, int, etc.) are left unchanged.
685 """
686 for i, op in enumerate(t.op):
687
688 context.clear_status()
689 t.maxcontext.clear_flags()
690
691 if op in RoundModes:
692 t.cop.append(op)
693 t.pop.append(op)
694 t.maxop.append(op)
695
696 elif not t.contextfunc and i == 0 or \
697 convstr and isinstance(op, str):
698 try:
699 c = C.Decimal(op)
700 cex = None
701 except (TypeError, ValueError, OverflowError) as e:
702 c = None
703 cex = e.__class__
704
705 try:
706 p = RestrictedDecimal(op)
707 pex = None
708 except (TypeError, ValueError, OverflowError) as e:
709 p = None
710 pex = e.__class__
711
712 try:
713 C.setcontext(t.maxcontext)
714 maxop = C.Decimal(op)
715 maxex = None
716 except (TypeError, ValueError, OverflowError) as e:
717 maxop = None
718 maxex = e.__class__
719 finally:
720 C.setcontext(context.c)
721
722 t.cop.append(c)
723 t.cex.append(cex)
724
725 t.pop.append(p)
726 t.pex.append(pex)
727
728 t.maxop.append(maxop)
729 t.maxex.append(maxex)
730
731 if cex is pex:
732 if str(c) != str(p) or not context.assert_eq_status():

Callers 7

test_unaryFunction · 0.70
test_binaryFunction · 0.70
test_ternaryFunction · 0.70
test_formatFunction · 0.70
test_roundFunction · 0.70
test_from_floatFunction · 0.70
test_quantize_apiFunction · 0.70

Calls 8

enumerateFunction · 0.85
RestrictedDecimalFunction · 0.85
strFunction · 0.85
raise_errorFunction · 0.85
clear_statusMethod · 0.80
clear_flagsMethod · 0.80
assert_eq_statusMethod · 0.80
appendMethod · 0.45

Tested by 7

test_unaryFunction · 0.56
test_binaryFunction · 0.56
test_ternaryFunction · 0.56
test_formatFunction · 0.56
test_roundFunction · 0.56
test_from_floatFunction · 0.56
test_quantize_apiFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…