From d27f42644d91e81ad4a85197d35851b1505f3c61 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Tue, 19 May 2020 02:36:00 +0400 Subject: [PATCH] Minor refactoring of Transaction class. --- piggybank/transaction.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/piggybank/transaction.py b/piggybank/transaction.py index dc16de0..0d1275b 100644 --- a/piggybank/transaction.py +++ b/piggybank/transaction.py @@ -2,9 +2,9 @@ from __future__ import annotations from time import strftime, strptime, gmtime -from typing import Optional +from typing import Optional, List -__all__ = ["Transaction", "TYPE_INCOME", "TYPE_OUTCOME"] +__all__ = ["Transaction", "TYPE_INCOME", "TYPE_OUTCOME", "TIME_FORMAT"] TYPE_INCOME = "in" TYPE_OUTCOME = "out" @@ -12,10 +12,14 @@ TIME_FORMAT = "%Y-%m-%dT%H:%M:%S" class Transaction: - """Transaction consists of a timestamp, a direction - and an array of coins. It doesn't depend on a currency. Only coins count is - stored.""" - def __init__(self, coins, direction: str = TYPE_INCOME, + """An object that holds a transaction. + + Arguments: + - coins -- a list of numbers represent count for each face value; + - direction -- is this income or outcome. Takes TYPE_INCOME + or TYPE_OUTCOME; + - timestamp -- date and time formated accordingly to TIME_FORMAT.""" + def __init__(self, coins: List[int], direction: str = TYPE_INCOME, timestamp: Optional[str] = None) -> None: self.coins = coins if direction in [TYPE_INCOME, TYPE_OUTCOME]: @@ -38,7 +42,7 @@ class Transaction: """Makes a Transaction object from its string output.""" timestamp, direction, coins = transaction.split() - coins = [int(coin) for coin in coins.split(",")] + coins = list(map(int, coins.split(","))) return Transaction(coins, direction, timestamp) def __str__(self) -> str: