Protocols vs ABCs
P28.protocols-abcs.01 · Audience: guest, it-ml, language-pro · Prerequisites: Records: class vs dataclass vs namedtuple
How do you say "any object that has these methods" in Python? Two answers:
structural typing with typing.Protocol — conformance by shape, no
inheritance — and nominal typing with abc.ABC — conformance by
subclassing. This track is about choosing between them, and it links forward to
P31 (Typing & Robust Code), where these tools meet mypy.
This first module makes duck typing explicit with a Protocol.
Ask the mentor about this module
Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.
Keeping your files on this device
Off by default. The mentor always gets your file; this only decides whether your own copy stays here. Copies live in this browser only - they do not follow you to another device, and clearing site data removes them.
Rung 1 — structural typing with Protocol
Loading exercise…
Interview rung — Protocols vs ABCs (free-form)
Loading exercise…
My notes on this module
Loading your notes...
Where next?
Later in Protocols & ABCs