fix string handling of DecimalElement#95
Conversation
|
Casting a Decimal to a float don't feel safe, precision can be lost. I'd prefer forcing the type to be a Decimal in the and removing the Also you can just remove the |
f3c9ff3 to
ede5203
Compare
|
you're absolutely right. I made the changes and it works as expected. |
* remove __str__() to ensure string type by falling back to inherited StringElement.__str__() * wrap __format__ method of _value * enforce Decimal() type in __init__
ede5203 to
fed25a8
Compare
|
In which part the |
Yes, in my case it's the jinja template that directly reads from the drafthorse document. It produces I think what's going on is, that But it's not limitied to jinja: With that I see no other way to solve that for any application besides accessing |
OK your PR looks good to me. But I'm not a contributor of the repo so I let the last word to those with the commit bit :) |
This fixes two aspects:
__str__()always returns a string (this closes DecimalElement.__str__() doesn't always return string type #94)__float__()method so python string formatting doesn't fail withTypeError: must be real number, not DecimalElement