Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions library.py
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
Copy link
Collaborator

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 (print and return str).

def print_longest_crime_audio_book(self) -> str:
crime_audio_books: list[Book] = []
max: Optional[Book] = None

# print banner
Copy link
Collaborator

Choose a reason for hiding this comment

The 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():
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not directly using _books variable?

if Genre.CRIME in b.genres:
if b._book_type == "Audio":
Comment on lines +19 to +20
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could merge this into one conditional expression using the & operator.

if max is not None and max.duration < b.duration:
Copy link
Collaborator

@NumericalMax NumericalMax Nov 22, 2023

Choose a reason for hiding this comment

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

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

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.


# Constructor
def __init__(self, books: list[Book]):
self._books = books
Comment on lines +37 to +38
Copy link
Collaborator

Choose a reason for hiding this comment

The 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] = []
Copy link
Collaborator

Choose a reason for hiding this comment

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

That one is not needed, as the constructor already initializes the variable _books. In the worst case it overwrites your initialized variable.


def get_books(self) -> list[Book]:
return self._books