summaryrefslogtreecommitdiff
path: root/type/money.py
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2022-02-10 14:52:14 -0800
committerScott Gasch <[email protected]>2022-02-10 14:52:14 -0800
commit2e8dd08f5f4f9624facf4d38ea6b276cc8131f56 (patch)
tree5d9982185ddb95c76669c594d20c2802e49ce89e /type/money.py
parente76081ebdfa078aa8508ba1682dacea80341157e (diff)
More cleanup.
Diffstat (limited to 'type/money.py')
-rw-r--r--type/money.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/type/money.py b/type/money.py
index 39557aa..b84652b 100644
--- a/type/money.py
+++ b/type/money.py
@@ -1,8 +1,10 @@
#!/usr/bin/env python3
+"""A class to represent money. See also centcount.py"""
+
import re
from decimal import Decimal
-from typing import Optional, Tuple, TypeVar
+from typing import Optional, Tuple
import math_utils
@@ -39,9 +41,9 @@ class Money(object):
a = round(a, 2)
s = f'{a:,.2f}'
if self.currency is not None:
- return '%s %s' % (s, self.currency)
+ return f'{s} {self.currency}'
else:
- return '$%s' % s
+ return f'${s}'
def __pos__(self):
return Money(amount=self.amount, currency=self.currency)
@@ -178,8 +180,8 @@ class Money(object):
def __ge__(self, other):
return self > other or self == other
- def __hash__(self):
- return self.__repr__
+ def __hash__(self) -> int:
+ return hash(self.__repr__)
AMOUNT_RE = re.compile(r"^([+|-]?)(\d+)(\.\d+)$")
CURRENCY_RE = re.compile(r"^[A-Z][A-Z][A-Z]$")