Skip to content

Commit 4e7fa49

Browse files
committed
Fix Ruff EM102 in grocery store cart exceptions
1 parent 9611435 commit 4e7fa49

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

other/grocery_store_cart.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ def __init__(self, price_catalog: dict[str, float]) -> None:
2525

2626
def add_item(self, item: str, quantity: int = 1) -> None:
2727
if item not in self.price_catalog:
28-
raise KeyError(f"{item!r} is not in the catalog")
28+
msg = f"{item!r} is not in the catalog"
29+
raise KeyError(msg)
2930
if quantity <= 0:
3031
raise ValueError("quantity must be positive")
3132
self.quantities[item] = self.quantities.get(item, 0) + quantity
@@ -35,7 +36,8 @@ def remove_item(self, item: str, quantity: int = 1) -> None:
3536
raise ValueError("quantity must be positive")
3637
current = self.quantities.get(item, 0)
3738
if current == 0:
38-
raise KeyError(f"{item!r} is not present in the cart")
39+
msg = f"{item!r} is not present in the cart"
40+
raise KeyError(msg)
3941
if (remaining := current - quantity) > 0:
4042
self.quantities[item] = remaining
4143
else:

0 commit comments

Comments
 (0)