Refactor currency enum, add currency format method#18
Refactor currency enum, add currency format method#18KunjPrasad wants to merge 2 commits intovimeo:masterfrom
Conversation
| class InvalidAmountError(ValueError): | ||
| def __init__(self): | ||
| super().__init__('Invalid amount for currency') | ||
| super().__init__("Invalid amount for currency") |
There was a problem hiding this comment.
Sigh! Didn't realize.. these changes are after running black on the files
| def from_sub_units(cls, sub_units: int, currency: Currency=Currency.USD): | ||
| def from_sub_units(cls, sub_units: int, currency: Currency = Currency.USD): | ||
| """Creates a Money instance from sub-units.""" | ||
| sub_units_per_unit = CurrencyHelper.sub_unit_for_currency(currency) |
There was a problem hiding this comment.
This is a concrete change. Removed CurrencyHelper. Instead the field is defined for Currency Enum
| #pylint: disable=too-many-lines | ||
| from babel.numbers import get_currency_symbol | ||
|
|
||
| class Currency(Enum): |
There was a problem hiding this comment.
Consolidated currency details inside Enum. Previously, the behavior was split between Currency and CurrencyHelper methods
| Taken from https://github.com/sebastianbergmann/money | ||
| """ | ||
| _CURRENCY_DATA = { | ||
| "AED": { |
There was a problem hiding this comment.
The changes are: (1) _CURRENCY_DATA is pulled out from within CurrencyHelper class; (2) The key of dictionary is a string. The format is useful for defining the Currency Enum
| sub_unit: int | ||
| # pylint: enable=invalid-name | ||
|
|
||
| @classmethod |
There was a problem hiding this comment.
Best is to consider it as deletion of entire CurrencyHelper class and making new Enum. The currency properties are now directly associated with the Enum
blackfor formatting