Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

solution #1240

wants to merge 1 commit into from

Conversation

kkkkkkkkatya
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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:

  1. 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.

  2. Key Existence Check: The check for 'wearing_a_mask' should ensure the key exists in the visitor dictionary. Using visitor.get('wearing_a_mask', True) can help handle cases where the key might be missing, ensuring the logic is robust.

  3. issues_found Variable: Since exceptions are raised immediately, the issues_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

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:

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"

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"

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.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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.

  1. Descriptive Error Messages: Ensure that exceptions raised in the visit_cafe method include descriptive messages. This will help in understanding the errors better.

  2. 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 after raise for cleaner code.

  3. Error Handling: In the go_to_cafe function, revise the logic to ensure all friends are checked before returning a result, especially when handling VaccineError.

  4. 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

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

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

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:

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"

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"

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"

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"

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:

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.

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.

2 participants