Skip to content

Ada AC2 - Supriya Chavan #13

Open
smchavan wants to merge 8 commits intoada-ac2:mainfrom
smchavan:main
Open

Ada AC2 - Supriya Chavan #13
smchavan wants to merge 8 commits intoada-ac2:mainfrom
smchavan:main

Conversation

@smchavan
Copy link
Copy Markdown

@smchavan smchavan commented Dec 9, 2022

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 Supriya! 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 Outdated
import uuid
from swap_meet.item import Item
class Clothing(Item):
def __init__(self,id= None,category = "" ,condition = 0 ,fabric = "Unknown" ):
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 seeing inconsistent spacing between parameters in functions and function calls across the files. When there is time, I suggest reviewing your code for style consistency across files before opening PRs. I often have this as part of my code clean up checklist. As far as spacing suggestions, I reccommend using a space after the comma separating parameters to add a little more visual separation.

def __init__(self, id = None, category = "", condition = 0, fabric = "Unknown"):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes I will also make a list of things to check for for refactoring and add this to it. Will make the changes. Thank you.

Comment thread swap_meet/electronics.py
self.type = type

def __str__(self):
item_message = super().__str__()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Really nice use of inheritance across the child classes 👍

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you.

Comment thread swap_meet/item.py Outdated
Comment on lines +6 to +9
if id is None :
self.id = uuid.uuid4().int
else:
self.id = id
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 solution, another option here could use conditional assignment:

# Assigns self.id to the parameter id if id is truthy, 
# otherwise assigns self.id the return value of uuid.uuid4().int
self.id = id if id else uuid.uuid4().int

Copy link
Copy Markdown
Author

@smchavan smchavan Dec 16, 2022

Choose a reason for hiding this comment

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

I was wondering the how would I raise value error if ID is not integer with this change?
In this example we can check it using test cases as well ?
I made the change in my code

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hmm, are you thinking about if the user passes in a non-integer id argument? In that case I'd likely add a guard statement at the top that checks if id is not None and the type of id is not an int - in that case we would raise an error. If we get past that statement then either the id argument was passed and has an int value, or it is None and we can create our default with uuid.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, I want to make sure if the id entered by user is not an integer it should raise an error. Yes the guard statement will be good at the beginning so if the id is not an int we don't need to assign the id to that instance object. Will make the changes. Thank you.

Comment thread swap_meet/item.py Outdated
# Wave 5
def condition_description(self):
description_of_condition = ["Mint","Heavily Used","Like New","Gently Used","Best Used","New"]
return description_of_condition[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?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

One option to have decimal condition values I can use multiple if statement to assign condition to the closest integer like if 1<self.condition < 2: self.condition = 1
again if it is 3.6 I want to round it to 4 . Thinking lambda function might help in some way to round the condition but stuck on it.
One idea came to my mind is while returning the condition description we can round the self.condition value as in
return description_of_condition[round(self.condition)]
the tests are passing and I edited the tests for decimal value and checked it. It works. Will try to think about lambda function usage.

Comment thread swap_meet/vendor.py Outdated
Comment on lines +10 to +13
if inventory is not None:
self.inventory = inventory
else:
self.inventory = []//I would like to know which is best practice in these two
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 is an unusual instance where I would suggest to explicitly check is not None instead of relying on the truthy or falsy value. Both ways are perfectly fine in most situations, but if we were short on memory, checking for truthiness would ignore if the user passed in an empty list and create a new empty list instance, since the empty list argument would evaluate to false.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Oh Ok,I was confused on this , but now understood. Will make the change. Thank you.

Comment thread swap_meet/vendor.py Outdated
Comment on lines +79 to +92
if self.inventory == []:
print("No inventory to display.")
return None

if category:
inventory_items_by_category = self.get_by_category(category)
if inventory_items_by_category:
for index in range(len(inventory_items_by_category)):
print(f"{index +1}. {inventory_items_by_category[index]}")
else:
print("No inventory to display.")
else:
for index in range(len(self.inventory)):
print(f"{index +1}. {self.inventory[index]}")
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 if-tree is pretty nested and we have very similar sections of looping and no inventory code. If we change the order of checks slightly to first resolve what list of items we want to iterate over, then error handle if it is empty, we can remove some of the if-else statements:

# If `category` is not empty or None, get a list of items with that category, 
# otherwise set `display_items` to `self.inventory`
display_items = self.get_by_category(category) if category else self.inventory
# The line above would be equivalent to
# if category:
#     display_items = self.get_by_category(category)
# else:
#     display_items = self.inventory

# Since we decided our list of items first, we get to combine 
# the error handling that was separated before
if not display_items:
    print("No inventory to display.") 
    return

# If we've gotten here, there must be an inventory to print
for index in range(len(self.inventory)):
    print(f"{index +1}. {self.inventory[index]}")

Copy link
Copy Markdown
Author

@smchavan smchavan Dec 18, 2022

Choose a reason for hiding this comment

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

Yes it saves lot of extra lines of code and it makes sense to get the items to be displayed by category if given or self inventory and then check if it is empty all at once. Thank you. I made the changes and it worked.

Comment thread swap_meet/vendor.py Outdated
if category:
inventory_items_by_category = self.get_by_category(category)
if inventory_items_by_category:
for index in range(len(inventory_items_by_category)):
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 range to give us an index to work with! Another way we could do this is with the enumerate function:

for index, item in enumerate(inventory_items_by_category, start=1): 
    print(f"{index}. {item}")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you. I keep forgetting to use enumerate. I should change it.

Comment on lines +52 to +54
assert result == None
assert item not in vendor.inventory
assert len(vendor.inventory) == 3
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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added these three assertions
assert "a" in vendor.inventory
assert "b" in vendor.inventory
assert "c" in vendor.inventory
Thank you.

Comment on lines +134 to +136
assert result == False
assert nobodys_item not in fatimah.inventory
assert nobodys_item not in jolie.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.

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

assert fatimah.inventory == [item_a, item_b, item_c]
assert jolie.inventory == []
assert item_a in fatimah.inventory
assert item_b in fatimah.inventory
assert item_c in fatimah.inventory

Added above assertions in the test . Thank you.


########### New Test for code covergae #############################
#@pytest.mark.skip
def test_choose_and_swap_items_with_other_inventory_category_given(monkeypatch):
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!

@smchavan
Copy link
Copy Markdown
Author

Great work Supriya! 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 =]

Thank you for your feedback and time. I will go through each one this weekend and get back to you if I have any questions about them.

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