Skip to content

Sapphire- Janice N#85

Open
janice15 wants to merge 16 commits into
Ada-C19:mainfrom
janice15:main
Open

Sapphire- Janice N#85
janice15 wants to merge 16 commits into
Ada-C19:mainfrom
janice15:main

Conversation

@janice15

@janice15 janice15 commented Apr 7, 2023

Copy link
Copy Markdown

No description provided.

@tildeee tildeee left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good work on this project, Janice! Because of the bugs and failing tests around the category features, this project is marked as a "yellow," asking you to review the project.

Overall, the features you've implemented are well-done; it's clean, straightforward, good code. Your test implementations look great. Your overall code style looks good. Keep it up!

My feedback is largely around some logical bugs I see around how you check the category in each item. In addition, I see a lot of opportunities in your classes to practice Inheritance.

Your git hygiene also looks pretty good! Keep up the frequency and quality of commit messages. This is a small "nitpicky" piece of feedback, but I think your commit messages would be better if they used the word "implemented" instead of "completed"-- simply because code is never "completed," so it feels weird to me to see a commit that claims it's completed lol :)

I'd encourage you to check your understanding/check the feedback on these concepts:

  • Instance methods
  • Inheritance
  • Debugging/confirming what your code is doing

Please let me know any and all questions that come up, especially if they're about those above three concepts!

Finally, in this project submission, on my end it looks like the tests for waves 2, 4, and 5 were still skipped.

Again, good work on this project. I want to make sure you can apply OOP principles to every project going forward, so let me know what questions you have or would like to review.

Comment thread swap_meet/vendor.py
self.inventory = inventory

def add(self, item):
self.item = 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.

Here, you're creating an instance variable on Vendor named item, and assigning it to the passed in item... meaning you're expecting every instance of Vendor (for example, instance_of_vendor = Vendor()) to store one single item, which we can access with instance_of_vendor.item

In this situation, we don't have a requirement that Vendors should have an item. Also, contextually, I'm not sure it makes sense that Vendors have one item... Especially since in this project they already have an inventory, which contains multiple items.

This is all to say, I think we can delete the line self.item = item!

Comment thread swap_meet/vendor.py
return item

def remove(self, item):
self.item = 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.

Similar to above, we don't ever access the instance variable item (only the passed-in argument item)... so we can delete this line, too.

Comment thread swap_meet/vendor.py
Comment on lines +35 to +39
self.inventory.remove(my_item)
self.inventory.append(their_item)

other_vendor.inventory.append(my_item)
other_vendor.inventory.remove(their_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.

These lines look suspiciously familiar to other code in this file! This is a good opportunity to use the other instance methods add and remove that are defined in Vendor. Consider this refactoring, which also passes the tests:

        self.remove(my_item)
        self.add(their_item)
        other_vendor.add(my_item)
        other_vendor.remove(their_item)

Comment thread swap_meet/vendor.py
their_item = other_vendor.inventory[0]


self.swap_items(other_vendor, my_item, their_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.

Nice use of swap_items!

Comment thread swap_meet/vendor.py
Comment on lines +66 to +67
if category not in self.inventory:
return 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.

I'm not sure this code does what you want it to do! self.inventory will always be a list of Item instances, whereas category will always be a string (such as "Clothing".) In most cases, category will not be in self.inventory.

Consider this Python snippet to demonstrate that:

from clothing import Clothing # Depending on where we write this test code snippet, we'll need to make sure we import/define Clothing

inventory = [Clothing(), Clothing(), Clothing()]
print("The contents of inventory are:", inventory)
category = "Clothing"
if category in inventory:
    print("Category Clothing is in this inventory of 3 Clothing instances") # Your current code logic says that this should be True if there's at least one Clothing item in the inventory.
else:
    print("Category Clothing is not in inventory of 3 Clothing instances")

When we run this, we'll find that the else branch prints, meaning that the similar if category not in self.inventory in your code will also behave similarly.

How do we find items in the inventory that have a category of "Clothing"? How do we look at each item and find its category? Your logic in get_by_category that uses Item's get_category instance method is the way to go here.

Comment thread swap_meet/vendor.py

my_item = my_priority
their_item = their_priority
self.swap_items(other_vendor, my_item, their_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.

In the requirements for swap_best_by_category, the value of my_priority and their_priority is a string that's a name of a category. In this code here, you're assigning my_item to this string, and then using it in swap_items (which expects an Item instance). Before we call swap_items, we'll need to accurately find the value for my_item and their_item.

Comment thread swap_meet/item.py
Comment on lines +26 to +28
for key, value in descriptions.items():
if key == self.condition:
print(value) 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.

Here, you're iterating through descriptions and printing the value of the keys matching self.condition. Our requirements for condition_description are to return it, not print it.

Comment thread swap_meet/clothing.py
@@ -1,2 +1,31 @@
import uuid
from swap_meet.item import Item
class Clothing:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Clothing should inherit from Item! Once it inherits from Item, we can rely on inheritance. We can delete the redundant definitions of get_category and condition_description in Clothing, so each instance of Clothing inherits get_category and condition_description from Item instead.

Comment thread swap_meet/electronics.py
Comment on lines +14 to +25
def condition_description(self):
descriptions = {0: "fair",
1: "poor",
2: "acceptable",
3: "gently used",
4: "Like new",
5: "Mint Condition",
}

for key, value in descriptions.items():
if key == self.condition:
print(value) 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.

Our project requirements state that condition_description should have the same behavior between Clothing, Decor, and Electronics. While having three identical implementations certainly works, these three inherit from Item... it would be good to take advantage of that, here!

If we delete condition_description here, then Electronics will look to its superclass (Item) for a definition of condition_description.

Comment thread swap_meet/decor.py
def __str__(self):
return f"An object of type Decor with id {self.id}. It takes up a {self.width} by {self.length} sized space."

def condition_desciption(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.

My comments about inheritance apply here, too.

However, I need to point out-- this method name is mispelled, and should be condition_description, not condition_desciption.

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