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