1
0

Fixed recursion error. Worked in 3.7.x, 3.8.x doesn't differ variables and properties of same name.

This commit is contained in:
Alexander "Arav" Andreev 2019-12-27 12:54:58 +04:00 committed by Alexander Arav Andreev
parent df0427ace4
commit 558257e674

View File

@ -18,11 +18,11 @@ class PiggyBank:
.pb files."""
def __init__(self, currency: str = DEFAULT_CURRENCY) -> None:
if currency.upper() in CURRENCIES:
self.currency = currency.upper()
self._currency = currency.upper()
else:
raise CurrencyIsNotSupportedError
self.transactions = []
self._transactions = []
def transact(self, coins: List[int], direction: str = TYPE_INCOME) -> None:
"""Make a transaction."""
@ -31,11 +31,11 @@ class PiggyBank:
f"currency's coins count ({len(coins)} "
f"!= {CURRENCIES[self.currency]['count']})")
self.transactions.append(Transaction(coins, direction))
self._transactions.append(Transaction(coins, direction))
for coin_count in self.count:
if coin_count < 0:
del self.transactions[-1]
del self._transactions[-1]
raise ValueError(
"You can't take out more than you have.")
@ -90,12 +90,12 @@ class PiggyBank:
else:
self.currency = currency
for transaction in _file:
self.transactions.append(Transaction.from_string(transaction))
self._transactions.append(Transaction.from_string(transaction))
@property
def currency(self) -> str:
"""Returns a currency of a PiggyBank."""
return self.currency
return self._currency
@currency.setter
def currency(self, currency: str) -> None:
@ -106,12 +106,12 @@ class PiggyBank:
raise CurrencyIsNotSupportedError
if CURRENCIES[currency]["count"] != CURRENCIES[self.currency]["count"]:
raise CurrenciesCoinCountMismatchError
self.currency = currency
self._currency = currency
@property
def transactions(self) -> List[Transaction]:
"""Returns a list of transactions."""
return self.transactions
return self._transactions
def __eq__(self, piggybank: PiggyBank) -> str:
"""It compares only currency."""