Conversation
| crime_audio_books: list[Book] = [] | ||
| max: Optional[Book] = None | ||
|
|
||
| # print banner |
There was a problem hiding this comment.
Quite redundant - not necessarily needed.
| # end else | ||
| # end for |
There was a problem hiding this comment.
The familiar Python reviewer will not need the information about ending for-loops as Python works with indents.
| def __init__(self, books: list[Book]): | ||
| self._books = books | ||
|
|
||
| _books: list[Book] = [] |
There was a problem hiding this comment.
That one is not needed, as the constructor already initializes the variable _books. In the worst case it overwrites your initialized variable.
| def __init__(self, books: list[Book]): | ||
| self._books = books |
There was a problem hiding this comment.
Usually, the constructor is placed on top of the class, before the function declaration starts.
| print("********* Longest Crime Audio Book **********") | ||
| print("*********************************************") | ||
|
|
||
| for b in self.get_books(): |
There was a problem hiding this comment.
Why not directly using _books variable?
| if Genre.CRIME in b.genres: | ||
| if b._book_type == "Audio": |
There was a problem hiding this comment.
You could merge this into one conditional expression using the & operator.
| for b in self.get_books(): | ||
| if Genre.CRIME in b.genres: | ||
| if b._book_type == "Audio": | ||
| if max is not None and max.duration < b.duration: |
There was a problem hiding this comment.
As you initialize the max with value None this condition never compute to true. Please add a further condition elif to address the case of max == None.
There was a problem hiding this comment.
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.
| for b in self.get_books(): | ||
| if Genre.CRIME in b.genres: | ||
| if b._book_type == "Audio": | ||
| if max is not None and max.duration < b.duration: |
There was a problem hiding this comment.
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.
| print(f"Author: {max.authors}") | ||
| print(f"Duration: {max.duration}") | ||
| print(f"______________________________") | ||
| return str(max) |
There was a problem hiding this comment.
max is of type Book. Therefore, casting it to a string is likely to fail and probably will not return the correct name. If you intend to return the title of the audiobook, then please access the title name. A proper naming of the variable max may help to address this issue in the future, e.g., max_duration_book.
|
|
||
| class Library(): | ||
|
|
||
| # Prints crime audio books |
There was a problem hiding this comment.
Please improve the documentation/commenting of the function. The return value is not clear, the described functionality (prints) is different from the actual function (print and return str).
No description provided.