Skip to content

Whales - K Frank#111

Open
kirfran wants to merge 10 commits intoada-c17:masterfrom
kirfran:master
Open

Whales - K Frank#111
kirfran wants to merge 10 commits intoada-c17:masterfrom
kirfran:master

Conversation

@kirfran
Copy link
Copy Markdown

@kirfran kirfran commented Apr 13, 2022

No description provided.

Copy link
Copy Markdown

@alope107 alope107 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job K! Very nice use of inheritance and re-use of methods. You've written some really DRY code here! This submission is green~

Comment thread swap_meet/clothing.py
Comment on lines +2 to +4
class Clothing(Item):
def __init__(self, category = "Clothing", condition = 0):
super().__init__(category, condition)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use of super here! Consider removing the category from the constructor arguments on line 3. We know we always want it to be "Clothing" so we don't want to allow changing it when instantiating an instance.

Comment thread swap_meet/electronics.py
Comment on lines +3 to +4
def __init__(self, category = "Electronics", condition = 0):
super().__init__(category, condition)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny style point here and elsewhere: when defining default arguments don't include spaces on either side of the equals sign. We would instead write it like:

def __init__(self, category="Electronics", condition=0):

Comment thread swap_meet/item.py
Comment on lines +9 to +21
def condition_description(self):
if self.condition == 0:
return "Poor"
if self.condition == 1:
return "Fair"
if self.condition == 2:
return "Good"
if self.condition == 3:
return "Very good"
if self.condition == 4:
return "Like new"
if self.condition ==5:
return "New" No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job having this be defined here once and inherited by the child classes!

Comment thread swap_meet/vendor.py
Comment on lines +9 to +12
def add(self, item):
'''Adds an item to a vendor's inventory'''
self.inventory.append(item)
return item
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great docstrings here and elsewhere!

Comment thread swap_meet/vendor.py
Comment on lines +4 to +7
def __init__(self, inventory=None):
if not inventory:
inventory = []
self.inventory = inventory
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job avoiding a mutable default object.

Comment thread swap_meet/vendor.py
Comment on lines +21 to +24
def get_by_category(self, category):
"Returns a list of items of a category in a vendor's inventory"
item_list = [item for item in self.inventory if item.category == category]
return item_list
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great comprehension!

Comment thread swap_meet/vendor.py
Comment on lines +36 to +39
def swap_first_item(self, vendor):
'''Swaps the first item in two vendor inventories (self and vendor)'''
if self.inventory and vendor.inventory:
return self.swap_items(vendor, self.inventory[0], vendor.inventory[0])
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love how you re-use your earlier method! One small bug here: according to the README this method should return False if either of the inventories is empty, but it actually returns None.

Comment thread swap_meet/vendor.py
Comment on lines +41 to +50
def get_best_by_category(self, category):
'''Returns the best item in vendor inventory by category. If multiple items, returns the item with the highest condition'''
items_list = self.get_by_category(category)
if not items_list:
return None
best_item = items_list[0]
for item in items_list:
if item.condition > best_item.condition:
best_item = item
return best_item
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great logic and re-use of method here!

Comment on lines +52 to +53
assert result == "c"
assert vendor.inventory == ["a", "b"]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice asserts!

Comment on lines +205 to +206
# - That the results is truthy
assert not result
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you may have accidentally copied a comment that says the opposite of what you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants