Skip to content

Sphinx Class_Astry & Rong#7

Open
cornetto9 wants to merge 20 commits into
Ada-C22:mainfrom
cornetto9:main
Open

Sphinx Class_Astry & Rong#7
cornetto9 wants to merge 20 commits into
Ada-C22:mainfrom
cornetto9:main

Conversation

@cornetto9

Copy link
Copy Markdown

No description provided.

@yangashley yangashley 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.

Nice job on swap-meet, Astry and Rong!

I can see from the commit history that you made frequent commits, which is great!

Let me know if you have any questions about my comments.

Comment thread swap_meet/clothing.py
@@ -1,2 +1,10 @@
class Clothing:
pass No newline at end of file
from swap_meet.item import 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 work importing Item since we're using by name as the parent class of Clothing 👍

Comment thread swap_meet/clothing.py
Comment on lines +4 to +5
def __init__(self, id=None, fabric="Unknown", condition=0):
super().__init__(id=id, condition=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 work on here!

On line 4 you correctly set the default value for fabric to "Unknown"

On line 5 you properly call the initializer of the parent, and pass along the values the child wants to use.

Comment thread swap_meet/item.py

class Item:
pass No newline at end of file
def __init__(self,id=None, condition=0, age=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.

Suggested change
def __init__(self,id=None, condition=0, age=0):
def __init__(self, id=None, condition=0, age=0):

Nit: You're missing a whitespace after the first comma. Be mindful to use/exclude whitespaces where necessary. It is easy to overlook, but having inconsistent use of whitespaces leads to a messy codebase.

Here's the section on whitespaces in the PEP8 styleguide.

Comment thread swap_meet/clothing.py
self.fabric = fabric

def __str__(self):
return f"An object of type Clothing with id {self.id}. It is made from {self.fabric} fabric."

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This method looks similar to the method you wrote in the Item parent class.

In that class __str__ returns f"An object of type Item with id {self.id}."

What if the __str__ method for the Clothing class could inherit this behavior from the parent class and then append the sentence with the second part of the fabric message "It is made from {self.fabric} fabric." ?

Currently, it's not possible because Item's __str__ method hardcodes the classtype "Item" in the string it returns. However, you could refactor the method to make it more dynamic so that it will print any class's name.

After Item's __str__ method is refactored, then Clothing's method could override it like this:

    def __str__(self):
        type_str = super().__str__()
        fabric_str = f"It is made from {self.fabric} fabric."
        return " ".join([type_str, fabric_str])

Comment thread swap_meet/decor.py
self.width = width
self.length = length

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

See comment from clothing.py about refactoring this method so it overrides the parent class's __str__ method.

Comment thread swap_meet/vendor.py
Comment on lines +94 to +107
def get_newest_item(self):
newest_item = self.inventory[0]

for item in self.inventory:
if item.age < newest_item.age:
newest_item = item

return newest_item

def swap_by_newest(self, other_vendor):
my_newest_item = self.get_newest_item()
their_newest_item = other_vendor.get_newest_item()

return self.swap_items(other_vendor, my_newest_item, their_newest_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.

👍 LGTM!

Comment on lines +21 to +30
assert len(fatimah.inventory) == 3
assert item_b in fatimah.inventory
assert item_a not in fatimah.inventory
assert item_c in fatimah.inventory
assert item_d in fatimah.inventory
assert len(jolie.inventory) == 2
assert item_d not in jolie.inventory
assert item_e in jolie.inventory
assert item_a in jolie.inventory
assert result 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.

LGTM! Gad you got some additional practice with this optional enhancement!

# *********************************************************************
# ****** Complete Assert Portion of this test **********
# *********************************************************************
assert result == False

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since the general intention of this method is to modify the inventory, we want to check this condition as well to make sure that the items that started in the inventory are still there. Adding these assertions would make the test more robust.

    assert len(vendor.inventory) == 3
    assert "a" in vendor.inventory
    assert "b" in vendor.inventory
    assert "c" in vendor.inventory

# *********************************************************************
assert len(jolie.inventory) == 0
assert len(fatimah.inventory) == 3
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.

More than be falsy, swap_items is intended to return an actual boolean. So while we typically write something like

    assert not result

in regular python, here we might prefer the more explicit check of

    assert result == False

You could make this test more robust by verifying that the items in the unchanged inventory are actually the items we started with (and not some other 3 items)

    assert item_a in fatimah.inventory
    assert item_b in fatimah.inventory
    assert item_c in fatimah.inventory

Comment on lines +157 to +158
assert item_f not in jesse.inventory
assert item_c not in tai.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.

We don't need to include the not in checks since the other checks already rule them out.

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.

3 participants