Python Glossary Русский

Python 3.3+Exceptionsexception

decimal.FloatOperation

module exceptions

Decimal and float were mixed while the FloatOperation trap is enabled.

Syntax

raise decimal.FloatOperation

The trap is off by default: mixing Decimal and float in the constructor or in comparisons is permitted and merely records a flag in the context. You enable it deliberately, to catch a stray float that sneaked into money arithmetic. Even when trapped, equality comparisons and explicit conversions such as Decimal.from_float() stay silent, and the class also inherits from TypeError.

Examples

import decimal
try:
    raise decimal.FloatOperation
except decimal.FloatOperation as e:
    print(type(e).__name__)   # → FloatOperation

See also

Open in the full glossarydocs.python.orgReport an inaccuracy