This pull request changes the datatype returned from the library to Decimal where floats are returned in the current version.
Rationale:
Using Decimal ensures precise handling of financial data, which is critical for the integrity of financial applications. The json library provides support through parse_float on decode and a helper cls for encoding. I have used a monkeypatched version and decided to contribute a clean version upstream. Here is what I did:
Convert to Using Decimal with json:
UPDATE:
Changed json parsing and added a decimaldecorder helper to seamlessly convert into and out of Decimal type when encoding an decoding json.
Update Tests:
Modified the existing tests to align with the changes introduced.
Specifically, fixed the test_make_request to ensure compatibility with handling of Decimal.
Changes Made:
Updated Import Statements:
Removed simplejson importing with import json.
Updated JSON Parsing:
Modified JSON parsing in the make_request method to use with parse_float=True.
Test Fix:
Adjusted the MockResponse class in the tests to ensure it uses the proper cis for JSON encoding.
Updated the test_make_request to mock the process_request method correctly with the changes.
Testing:
Unit Tests: All existing unit tests have been updated and pass successfully.
Manual Testing: Conducted manual testing to ensure that the changes do not introduce any regressions.
Additional Notes:
Backward Compatibility: This change could break other projects that expect the amounts to be in floats, expecially if they are serializing the data. In general, however, Decimals work almost everywhere in python where floats work and I think anyone doing maths for currencies have, like me, been converting to Decimal all along anyway.
Documentation: No changes have been made yet I wanted to get feedback first before investing more time.
This pull request changes the datatype returned from the library to Decimal where floats are returned in the current version.
Rationale:
Using Decimal ensures precise handling of financial data, which is critical for the integrity of financial applications. The json library provides support through parse_float on decode and a helper cls for encoding. I have used a monkeypatched version and decided to contribute a clean version upstream. Here is what I did:
Convert to Using Decimal with json:
UPDATE:
Changed json parsing and added a decimaldecorder helper to seamlessly convert into and out of Decimal type when encoding an decoding json.
Update Tests:
Modified the existing tests to align with the changes introduced. Specifically, fixed the test_make_request to ensure compatibility with handling of Decimal.
Changes Made:
Test Fix:
Testing:
Additional Notes:
Backward Compatibility: This change could break other projects that expect the amounts to be in floats, expecially if they are serializing the data. In general, however, Decimals work almost everywhere in python where floats work and I think anyone doing maths for currencies have, like me, been converting to Decimal all along anyway.
Documentation: No changes have been made yet I wanted to get feedback first before investing more time.