ChrisCScott / forecaster

A personal finances forecasting tool for Canadian retirement planning
Other
1 stars 2 forks source link

Manage high-precision mode application-wide #79

Open ChrisCScott opened 2 years ago

ChrisCScott commented 2 years ago

This issue involves implementing a revised solution for issue #77. As suggested in a comment to that issue:

Consider using contextvars for high-precision conversion. (See PEP 567 for more on this, as well as this Stack Overflow article.)

This might run afoul of the general prohibition on global variables, but it's how decimal manages consistent precision and it seems appropriate if we think of native-precision/high-precision operating modes as different states of the application as a whole. (Since it is necessary that if one part of the application is using a type like Decimal, then all parts of the application need to use it.)

This might need to be a separate issue. Since implementation of a fix for this issue is already most of the way to complete, it might be a refactor to be done after the initial implementation is working.

A benefit of this is that we can avoid passing high_precision arguments between objects throughout the library, as is done now.