-
Notifications
You must be signed in to change notification settings - Fork 1
Group 1 - refactoring library class #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| from typing import Optional | ||
| from library.model.book import Book | ||
| from library.model.genre import Genre | ||
|
|
||
|
|
||
| class Library(): | ||
|
|
||
| # Prints crime audio books | ||
| def print_longest_crime_audio_book(self) -> str: | ||
| crime_audio_books: list[Book] = [] | ||
| max: Optional[Book] = None | ||
|
|
||
| # print banner | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quite redundant - not necessarily needed. |
||
| print("*********************************************") | ||
| print("********* Longest Crime Audio Book **********") | ||
| print("*********************************************") | ||
|
|
||
| for b in self.get_books(): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not directly using |
||
| if Genre.CRIME in b.genres: | ||
| if b._book_type == "Audio": | ||
|
Comment on lines
+19
to
+20
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could merge this into one conditional expression using the |
||
| if max is not None and max.duration < b.duration: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you initialize the
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please be aware, that there might be audiobooks of same max length. Is it intended that only the first one will be returned? If so, please add this to the documentation of the function. Right now you function documentation suggests that multiple books are the return. |
||
| max = b | ||
| # end if | ||
| # end if | ||
| else: | ||
| pass | ||
| # end else | ||
| # end for | ||
|
Comment on lines
+27
to
+28
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The familiar Python reviewer will not need the information about ending for-loops as Python works with indents. |
||
|
|
||
| print(f"Title: {max.title}") | ||
| print(f"Author: {max.authors}") | ||
| print(f"Duration: {max.duration}") | ||
| print(f"______________________________") | ||
| return str(max) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| # Constructor | ||
| def __init__(self, books: list[Book]): | ||
| self._books = books | ||
|
Comment on lines
+37
to
+38
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usually, the constructor is placed on top of the class, before the function declaration starts. |
||
|
|
||
| _books: list[Book] = [] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That one is not needed, as the constructor already initializes the variable |
||
|
|
||
| def get_books(self) -> list[Book]: | ||
| return self._books | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please improve the documentation/commenting of the function. The return value is not clear, the described functionality (
prints) is different from the actual function (printandreturn str).