Skip to content

Ocelots - Kelly T#21

Open
kellytate wants to merge 21 commits intoada-ac2:mainfrom
kellytate:main
Open

Ocelots - Kelly T#21
kellytate wants to merge 21 commits intoada-ac2:mainfrom
kellytate:main

Conversation

@kellytate
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@kelsey-steven-ada kelsey-steven-ada left a comment

Choose a reason for hiding this comment

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

Great work Kelly! I've left a mix of suggestions and questions to consider for feedback. Please reply here on Github or reach out on Slack if there's anything I can clarify =]

Comment thread swap_meet/clothing.py
super().__init__(id, condition)
self.fabric = fabric

def get_attribute(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I fully see what you were doing with get_attribute function, and it is a really neat solution to the issue. However, I think we're bending the guidelines of OOP design with how it's implemented. Name-wise, another developer unfamiliar with the project might have some confusion around what determines what of the several attributes the class holds is returned by a function get_attribute. If it's a function all child classes have, generally we would define it in the parent class so the children could inherit and override as necessary. I'd need to think a bit more about if there is a specific pattern that would work better, but one suggestion would be to give the parent class a function like get_comparison_key that each of the children can override.

Comment thread swap_meet/clothing.py
fabric attribute.
"""

def __init__(self, fabric = "Unknown", id = None, condition = 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.

Nice use of default values.

Comment thread swap_meet/item.py
Comment on lines +7 to +13
if id is not None:
if type(id) is not int:
raise ValueError("invalid id input")
else:
self.id = id
else:
self.id = uuid.uuid1().int
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we could simplify the if/else tree a little by combining our validation checks:

if id is not None and type(id) is not int:
    raise ValueError("invalid id input")

self.id = id if id else uuid.uuid1().int

Comment thread swap_meet/item.py
4 : "not bad",
5 : "excellent"
}
return switch.get(self.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.

Nice handling for condition description! It looks like the code assumes that self.condition will always be an integer, but what if we allowed decimals like a condition of 3.5? How could we adapt our code to convert the decimal to an int we could use here, or alternately, change the if-statements to support decimals?

Comment thread swap_meet/vendor.py
def get_by_id(self, id):
"""Gets item by item id from list of inventory. Returns Item object."""

item = next((item for item in self.inventory if item.id == id), None)
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 use of next with a None default!

Comment thread swap_meet/vendor.py
items = self.get_by_category(category) if category else self.inventory
if items:
for i, item in enumerate(items, 1):
print(f"{i}. {str(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.

Because we have implemented the __str__ method, this is one of the situations where python will implicitly call it for us, we don't need to wrap item in a call to str:

print(f"{i}. {item}")

Comment thread swap_meet/vendor.py

items = self.get_by_category(category) if category else self.inventory
if items:
for i, item in enumerate(items, 1):
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 for enumerate!

Comment on lines +56 to +58
assert len(vendor.inventory) == 3
assert item not in vendor.inventory
assert result is None
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 assertions, I would also suggest checking the inventory contents, since checks like the length being correct do not guarantee that the individual elements are still what we expect.

Comment on lines +138 to +140
assert len(fatimah.inventory) == 3
assert len(jolie.inventory) == 0
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.

The feedback in wave 1 applies here as well, what else would be helpful to assert to ensure there were no unintended side effects?

items = vendor.get_by_category_attribute("Electronics", "radio")

assert items == []
assert len(items) == 0 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.

Very nice, love the new tests =]

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