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
{{ message }}
Repository navigation
decimal.Decimal not handled in preconf converters (json, pyyaml) #761
Bug: decimal.Decimal crashes in preconf converters
Problem
decimal.Decimal is a very common stdlib type in financial and e-commerce applications, but none of the preconf converters handle it. Both unstructure and structure operations fail.
Reproduction
importdecimalimportattrsfromcattrs.preconf.jsonimportmake_converter@attrs.defineclassOrder:
amount: decimal.Decimalconv=make_converter()
o=Order(amount=decimal.Decimal('19.99'))
# Unstructure passes through the raw Decimal object — not JSON serializableconv.dumps(o)
# → TypeError: Object of type Decimal is not JSON serializable# Structure fails entirelyconv.structure({'amount': '19.99'}, Order)
# → StructureHandlerNotFoundError: Unsupported type: <class 'decimal.Decimal'>. Register a structure hook for it.
Same crash with the pyyaml preconf:
fromcattrs.preconf.pyyamlimportmake_converterconv=make_converter()
conv.dumps(Order(amount=decimal.Decimal('19.99')))
# → RepresenterError: cannot represent an object: Decimal('19.99')
Expected Behavior
The json and pyyaml preconf converters should handle decimal.Decimal out of the box:
Unstructure: Decimal → str (preserving full precision — NOT float, which loses precision for values like Decimal('0.1'))
This addition will help me out a lot thanks @Binilkks
@Tinche Would you be interested in incorporating a Discussions tab (ie. https://github.com/agronholm/apscheduler/discussions)? I have some random questions but I know you try to keep the issues down and I wouldn't really consider my questions issues anyway. If not no big deal just figured it might make sense.
Activity
Add Decimal support to json and pyyaml preconf converters (closes pyt…
chisox721 commentedon Jul 17, 2026
This addition will help me out a lot thanks @Binilkks
@Tinche Would you be interested in incorporating a Discussions tab (ie. https://github.com/agronholm/apscheduler/discussions)? I have some random questions but I know you try to keep the issues down and I wouldn't really consider my questions issues anyway. If not no big deal just figured it might make sense.
Tinche commentedon Jul 18, 2026
I talked to @hynek and he had no objections, so I've enabled the Discussions tab!