Instance vs class attributes — and the bug AI ships every time — step 9 of 9
Checkpoint
One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.
Last drill. Build a User class that uses both buckets correctly:
- Class attribute
domain = "example.com"(a constant — same for every user). - Instance attributes (assigned in
__init__):username(passed in)permissions— an empty list (must be per-instance)
- Method
email()returnsf"{self.username}@{self.domain}". - Method
grant(perm)appendspermtoself.permissions.
Two users, distinct permission lists, shared domain string.
Expected output:
[email protected]
[email protected]
['read']
['read', 'write']
⌘↵ runs the editor.read, then continue.
Checkpoint
One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.
Last drill. Build a User class that uses both buckets correctly:
- Class attribute
domain = "example.com"(a constant — same for every user). - Instance attributes (assigned in
__init__):username(passed in)permissions— an empty list (must be per-instance)
- Method
email()returnsf"{self.username}@{self.domain}". - Method
grant(perm)appendspermtoself.permissions.
Two users, distinct permission lists, shared domain string.
Expected output:
[email protected]
[email protected]
['read']
['read', 'write']
this step needs the editor
on desktop today; in the app (coming soon). save your spot and we'll bring you back here when you're ready.