Skip to content

Solution to review – TO MASTER - #1

Open
Sn1kls wants to merge 1 commit into
masterfrom
solution-to-review
Open

Solution to review – TO MASTER#1
Sn1kls wants to merge 1 commit into
masterfrom
solution-to-review

Conversation

@Sn1kls

@Sn1kls Sn1kls commented Jun 23, 2026

Copy link
Copy Markdown
Owner

No description provided.

@Sn1kls Sn1kls left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Nice work – the logic correctly covers all three scenarios from the README. Key fixes before approval: inherit from Exception, use parenthesised imports, compare to None with is, and add type hints (which also clears the unused import). The rest are minor style nits. Requesting changes – you're close)))

Comment thread app/cafe.py
@@ -0,0 +1,19 @@
from app.errors import NotVaccinatedError, \
OutdatedVaccineError, \
NotWearingMaskError

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Use parentheses for multi-line imports instead of backslash continuation. You already do this in main.py (lines 2–4), so it's mainly about keeping one consistent style across the project. It's also the approach PEP 8 prefers for wrapping long lines.

Comment thread app/cafe.py
from app.errors import NotVaccinatedError, \
OutdatedVaccineError, \
NotWearingMaskError
import datetime

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Imports should be grouped – standard library first, then third-party, then local app – with a blank line between groups (PEP 8 – Imports). So datetime (standard library) belongs above app.errors (local), separated by a blank line.

Note: default flake8 doesn't check import order (isort does)

Comment thread app/cafe.py
def __init__(self, name: str) -> None:
self.name = name

def visit_cafe(self, vstr: dict) -> str:

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

vstr is hard to read – the README calls this parameter visitor. A descriptive name makes the method self-documenting, so please rename it.

Comment thread app/cafe.py
self.name = name

def visit_cafe(self, vstr: dict) -> str:
if "vaccine" not in vstr.keys() or vstr["vaccine"] == None:

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Two small fixes: drop .keys() ("vaccine" not in visitor is enough), and compare to None with is, not ==. PEP 8 is explicit: "Comparisons to singletons like None should always be done with is or is not, never the equality operators." (flake8 flags this as E711)

Comment thread app/cafe.py
elif not vstr["wearing_a_mask"]:
raise NotWearingMaskError("not wearing mask")
else:
return "Welcome to " + self.name

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Prefer an f-string for readability and consistency: return f"Welcome to {self.name}" (PEP 498)

Comment thread app/errors.py
@@ -0,0 +1,14 @@
class NotWearingMaskError(BaseException):

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Custom exceptions should inherit from Exception. BaseException is reserved for system-exiting signals like SystemExit and KeyboardInterrupt, so an error derived from it won't be caught by a normal except Exception – which is surprising and easy to break later. The Python tutorial puts it directly: "Exceptions should typically be derived from the Exception class, either directly or indirectly."

Comment thread app/errors.py


class OutdatedVaccineError(VaccineError):
pass No newline at end of file

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

The file should end with a newline after the last line (flake8 W292)

Comment thread app/main.py
OutdatedVaccineError)


def go_to_cafe(friends, cafe) -> str:

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

The parameters have no type hints – checklist point 5.

Annotating cafe: Cafe also puts the Cafe import on line 1 to use – it's currently unused and flagged as flake8 F401, so this is cleaner than deleting the import.

Comment thread app/main.py
def go_to_cafe(friends, cafe) -> str:
total = 0

for i in range(len(friends)):

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

You can loop over the list directly – for friend in friends: instead of indexing with range(len(...)). It's the more idiomatic and readable form (Python for statements).

Comment thread app/main.py
if total:
return f'Friends should buy {total} masks'
else:
return f'Friends can go to {cafe.name}'

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Same else after return as in cafe.py – safe to drop (checklist point 4). Renaming total to something like masks_to_buy would also make the intent clearer.

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.

1 participant