You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bool is an int subclass in Python, so isinstance(True, (int, float)) is True and the value falls into the int/float branch of _coerce_decimal. Decimal(str(True)) then attempts Decimal('True') and raises decimal.InvalidOperation('[<class ConversionSyntax>]').
That is a confusing low-level error for a foot-gun (passing True for a price or count is almost always a typo — is_yes=True accidentally tabbed into count=True). The SDK should fail clearly.
Add an explicit bool check before the (int, float) branch:
def_coerce_decimal(value: Any) ->Decimal:
ifisinstance(value, Decimal):
returnvalueifisinstance(value, bool):
raiseTypeError(
"Cannot convert bool to Decimal — bool is an int subclass, ""so this is almost always a typo (did you mean count=1?)."
)
ifisinstance(value, (int, float)):
returnDecimal(str(value))
...
Mirror the check in to_decimal. Add unit test: test_coerce_decimal_rejects_bool.
Activity