-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
solution #1240
base: master
Are you sure you want to change the base?
solution #1240
Conversation
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.
Thank you for your hard work on this pull request! 😊 While your solution meets many of the task requirements, there are a few critical issues that need to be addressed before we can approve it:
-
Error Handling Logic: The current implementation raises exceptions immediately, which prevents the function from checking all friends for issues. This means that only the first issue encountered is reported, potentially missing others. Consider collecting all issues first and returning a summary after the loop to ensure comprehensive error reporting.
-
Key Existence Check: The check for
'wearing_a_mask'
should ensure the key exists in the visitor dictionary. Usingvisitor.get('wearing_a_mask', True)
can help handle cases where the key might be missing, ensuring the logic is robust. -
issues_found
Variable: Since exceptions are raised immediately, theissues_found
variable will never be greater than 1. You might want to remove it or adjust its usage to align with collecting multiple issues before raising an exception.
These changes are important to ensure that the code functions correctly and meets the core requirements of the task. Once these issues are addressed, your solution will be much stronger. Keep up the great work, and I look forward to seeing your improvements! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
self.name = name | ||
|
||
def visit_cafe(self, visitor: dict) -> str: | ||
issues_found = 0 |
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.
The issues_found
variable is incremented, but since an exception is raised immediately after, it will never be greater than 1. Consider removing issues_found
or using it differently if you intend to collect multiple issues before raising an exception.
if visitor["vaccine"]["expiration_date"] < date.today(): | ||
issues_found += 1 | ||
raise OutdatedVaccineError | ||
if "wearing_a_mask" in visitor: |
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.
The check for 'wearing_a_mask' should ensure that the key exists in the visitor dictionary. Consider using if visitor.get('wearing_a_mask', True) is False:
to handle cases where the key might be missing.
cafe.visit_cafe(friend) | ||
except VaccineError: | ||
issues_found += 1 | ||
return "All friends should be vaccinated" |
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.
Returning immediately after catching a VaccineError
means the function will exit on the first unvaccinated friend, potentially missing other issues. Consider collecting all issues first and returning a summary after the loop.
issues_found += 1 | ||
masks_to_buy += 1 | ||
if masks_to_buy != 0: | ||
return f"Friends should buy {masks_to_buy} masks" |
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.
Returning immediately after determining the number of masks to buy might prevent checking all friends. Consider collecting all issues first and returning a summary after the loop.
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.
Great job on implementing the core functionality of the Cafe
class and related components! 🎉 While your code meets most of the task requirements, there are a few areas for improvement to enhance clarity and maintainability.
-
Descriptive Error Messages: Ensure that exceptions raised in the
visit_cafe
method include descriptive messages. This will help in understanding the errors better. -
Code Style: Follow the checklist guidelines for using double quotes and ensure each file ends with a single blank line. Also, consider removing unnecessary
else
statements afterraise
for cleaner code. -
Error Handling: In the
go_to_cafe
function, revise the logic to ensure all friends are checked before returning a result, especially when handlingVaccineError
. -
Error Class Descriptions: Update the
__str__
methods in your error classes to return more descriptive messages, providing clarity when an error is raised.
These improvements will not only make your code more robust but also enhance readability and maintainability. Keep up the good work, and use this feedback to refine your skills further. Remember, addressing these issues will be crucial for future projects. Happy coding! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
issues_found = 0 | ||
if "vaccine" not in visitor: | ||
issues_found += 1 | ||
raise NotVaccinatedError |
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.
The NotVaccinatedError
should be raised with a descriptive message. According to the checklist, you should provide a message when raising exceptions, e.g., raise NotVaccinatedError('Visitor is not vaccinated.')
.
else: | ||
if visitor["vaccine"]["expiration_date"] < date.today(): | ||
issues_found += 1 | ||
raise OutdatedVaccineError |
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.
The OutdatedVaccineError
should be raised with a descriptive message. Consider using raise OutdatedVaccineError('Visitor's vaccine is outdated.')
to comply with the checklist requirement for descriptive error messages.
if "wearing_a_mask" in visitor: | ||
if visitor["wearing_a_mask"] is False: | ||
issues_found += 1 | ||
raise NotWearingMaskError |
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.
The NotWearingMaskError
should be raised with a descriptive message. You can use raise NotWearingMaskError('Visitor is not wearing a mask.')
to provide a clear error message as per the checklist.
if "vaccine" not in visitor: | ||
issues_found += 1 | ||
raise NotVaccinatedError | ||
else: |
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.
The use of else
after a raise
statement is unnecessary. According to the checklist, avoid using unnecessary else
blocks. You can directly check the condition without else
.
|
||
class NotVaccinatedError(VaccineError): | ||
def __str__(self) -> str: | ||
return "NotVaccinatedError" |
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.
The __str__
method for NotVaccinatedError
should return a more descriptive message. Consider returning something like 'Visitor is not vaccinated.' to provide clarity when the error is raised.
|
||
class OutdatedVaccineError(VaccineError): | ||
def __str__(self) -> str: | ||
return "OutdatedVaccineError" |
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.
The __str__
method for OutdatedVaccineError
should return a more descriptive message. You might want to return 'Visitor's vaccine is outdated.' to give a clear indication of the issue.
|
||
class NotWearingMaskError(Exception): | ||
def __str__(self) -> str: | ||
return "NotWearingMaskError" |
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.
The __str__
method for NotWearingMaskError
should return a more descriptive message. Consider using 'Visitor is not wearing a mask.' to provide a clear error message.
cafe.visit_cafe(friend) | ||
except VaccineError: | ||
issues_found += 1 | ||
return "All friends should be vaccinated" |
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.
Returning immediately after a VaccineError
is caught means that not all friends will be checked. If the intention is to check all friends, consider accumulating the issues and returning a summary after the loop.
masks_to_buy += 1 | ||
if masks_to_buy != 0: | ||
return f"Friends should buy {masks_to_buy} masks" | ||
if issues_found == 0: |
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.
The condition if issues_found == 0:
assumes that no issues mean all friends can go to the cafe. However, if a VaccineError
is encountered, the function returns early, so this condition might not be reached as expected. Consider revising the logic to ensure all friends are evaluated before making a decision.
No description provided.