Skip to content

C22 - Sphinx - Priyanka and Tatiana#1

Open
Nerpassevera wants to merge 50 commits intoAda-C22:mainfrom
Nerpassevera:main
Open

C22 - Sphinx - Priyanka and Tatiana#1
Nerpassevera wants to merge 50 commits intoAda-C22:mainfrom
Nerpassevera:main

Conversation

@Nerpassevera
Copy link

No description provided.

@Nerpassevera
Copy link
Author

Nerpassevera commented Oct 4, 2024

Alternative function implementations created after discovering higher-order functions:

    def get_by_id(self, item_id):
        result = next(filter(lambda item: item.id == item_id, self.inventory), None)
        return result
    def get_by_category(self, category):
        result = list(filter(lambda item: item.get_category() == category.capitalize(), self.inventory))
        return result
    def get_best_by_category(self, category):
        items_in_category = self.get_by_category(category)
        if items_in_category:
            result = max(items_in_category, key=lambda item: item.condition, default=None)
            return result
            ```

@Nerpassevera
Copy link
Author

Nerpassevera commented Oct 4, 2024

We practiced writing docstrings for classes and methods. @yangashley, could you please give us feedback on this subject too?

@yangashley
Copy link

@Nerpassevera When writing docstrings you should adhere to some style for consistency. What style is used depends on team preferences so I can't speak to which specific style you should use.

Docstrings should ideally contain all information that is relevant for using that class or method. Normally, that is less about describing the details of how the code works, and more about describing the purpose and general behavior.

A couple example of guides:

Copy link

@yangashley yangashley left a comment

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, Priyanka and Tatiana!

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.

- `my_priority`, which represents a category that the `Vendor` wants to receive
- `their_priority`, which represents a category that `other_vendor` wants to receive
- The best item in my inventory that matches `their_priority` category is swapped with the best item in `other_vendor`'s inventory that matches `my_priority`
- If `other_vendor` has no item that matches `my_priority` category, swapping does not happen, and it returns `False`
Copy link

@yangashley yangashley Oct 7, 2024

Choose a reason for hiding this comment

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

Was this change accidentally committed?

If this change wasn't needed then take care to remove it from the list of files being added and committed. You can unstage a file for commit if you haven't run git commit yet and you can look at how to locally revert a commit if you already added/committed the file.

In industry, when you write code and open a PR it means you're asking to merge code into the main branch. Therefore, you will not be permitted to merge in changes that are not part of your feature work because it will cause noise in the commit history or bring in unnecessary changes to the codebase.

It's best practice to run git status to see what changes will be committed before you commit so you can catch stray changes like this.

Comment on lines +4 to +21
"""
A subclass of Item that represents an item of clothing.

Parameters:
----------
id : int, optional
Id of the item. Generated randomly by default
fabric : str, optional
Type of fabric the item is made of. Defaults to "Unknown"
condition : int, optional
An integer value representing the condition of the item,
where 1 is the worst and 5 is the best. Must be between 1 and 5.
Defaults to 0, indicating that no condition is unknown.
age : tuple, optional
A tuple of 3 integer representing date in format (yyyy, mm, dd).
Defaults to current day.

"""

Choose a reason for hiding this comment

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

If you were using Google's docstring guide for Python, then you can follow the info found in the guide here about writing docstrings for a class

@@ -1,2 +1,31 @@
class Clothing:
pass No newline at end of file
from .item import Item

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 on lines +24 to +25
super().__init__(id, condition, age)
self.fabric = fabric

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 23 you correctly set the default value for fabric to "Unknown".

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

Lastly, good work remembering to refactor the function definition to include age so that it can get set from the subclass

Comment on lines +29 to +31
item_type_line, produce_date_line = super().generate_description()
item_fabric_line = f"It is made from {self.fabric} fabric."
return "\n".join([item_type_line, item_fabric_line, produce_date_line])

Choose a reason for hiding this comment

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

You could also do a one line return like:

f"{super().__str__()} It is made from {self.fabric} fabric."

assert result
assert len(tai.inventory) == 3
assert len(jesse.inventory) == 3
assert jesse.inventory == [item_d, item_e, item_c]

Choose a reason for hiding this comment

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

This assertions will fail if the order of items in each list somehow change. The README didn't specify that the order of inventory items needed to be maintained, so we probably don't need to constrain our tests and therefore our functions to these requirements. In fact, if you were to implement the swap that I suggested in a comment using multiple assignment, then these tests could fail because the order of elements would be changed.

While more verbose, you can check that elements are in a list like:

    assert item_d in jesse.inventory
    assert item_e in jesse.inventory
    assert item_c in jesse.inventory

And since we're checking Jesse's inventory, it would be make the test more thorough to also check the items in Tai's inventory too.

# *********************************************************************
# ****** Complete Assert Portion of this test **********
# *********************************************************************
assert not result

Choose a reason for hiding this comment

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

swap_best_by_category should return False if a swap doesn't happen. More than be falsy, result 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

Same comment applies to similar assertion written in another test below.

Comment on lines +235 to +236
assert tai.inventory == [item_a, item_b, item_c]
assert jesse.inventory == [item_d, item_e, item_f]

Choose a reason for hiding this comment

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

Do we need to consider order when checking the inventories of these vendors? If not, we don't need to test for it here.

Same comment applies to similar assertions written in another test below.

Comment on lines +327 to +331
print(f"{tai.inventory=}")
print(f"{jesse.inventory=}")
exchanged = tai.swap_by_newest(jesse)
print(f"{tai.inventory=}")
print(f"{jesse.inventory=}")

Choose a reason for hiding this comment

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

Remove debugging print statements when you're finished with them so they're not part of the PR.

Comment on lines +337 to +338
assert tai.inventory == [ item_b, item_a, item_f]
assert jesse.inventory == [ item_e, item_d, item_c ]

Choose a reason for hiding this comment

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

Nit: inconsistent whitespaces around square brackets.

Suggested change
assert tai.inventory == [ item_b, item_a, item_f]
assert jesse.inventory == [ item_e, item_d, item_c ]
assert tai.inventory == [item_b, item_a, item_f]
assert jesse.inventory == [item_e, item_d, item_c]

Copy link

@PriyankaKaramchandani PriyankaKaramchandani left a comment

Choose a reason for hiding this comment

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

@yangashley @Nerpassevera: Ashley I wanted to ask: when ever I want to pull changes of my team it asks me to always make my commits first. Only if I have made commits it allows me to proceed with git pull.
I read about stashing my changes with: git stash or git stash pull. Should I be using that?

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