Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 09c4a69

Browse files
committed
refactor: enforced the signs for income and expense creation methods instead of raising errors
1 parent 093f979 commit 09c4a69

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

projects/Expense-Tracker/item.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,14 @@ def create(cls, name: str, amount: float, description: str, date_str: str, categ
4545
def create_expense_item(cls, name: str, amount: float, description: str, date_str: str,
4646
category: Optional[Category] = None):
4747
if amount >= 0:
48-
raise ValueError('Expense Item cannot be positive.')
48+
return cls.create(name, -abs(amount), description, date_str, category=category)
4949

5050
return cls.create(name, amount, description, date_str, category=category)
5151

5252
@classmethod
5353
def create_income_item(cls, name: str, amount: float, description: str, date_str: str,
5454
category: Optional[Category] = None):
55-
if amount <= 0:
56-
raise ValueError('Income Item cannot be negative.')
57-
58-
return cls.create(name, amount, description, date_str, category=category)
55+
return cls.create(name, abs(amount), description, date_str, category=category)
5956

6057
@classmethod
6158
def from_json_str(cls, json_str):

0 commit comments

Comments
 (0)