Challenge 2: A Protocol for Comparable Items — Possible Solution ==================================================================== from typing import Protocol class HasArea(Protocol): def area(self) -> float: ... class Square: def __init__(self, side): self.side = side def area(self): return self.side ** 2 def describe(shape: HasArea) -> str: return f"Area is {shape.area()}" print(describe(Square(4))) Output: Area is 16 WHY THIS WORKS AS AN ANSWER ------------------------------ class HasArea(Protocol): with def area(self) -> float: ... reuses this chapter's own Honker(Protocol) example structure exactly — declaring the SHAPE a class must have (a callable area() method returning a number) without requiring any class to actually inherit from HasArea. class Square: is reused directly from Course 2, Chapter 2's Shape Hierarchy challenge — deliberately UNCHANGED here, with no reference to HasArea or Protocol anywhere in its own definition, exactly mirroring the chapter's own Car class that never inherited from Honker either. describe(shape: HasArea) -> str: reuses this chapter's own make_it_honk(thing: Honker) function shape — the parameter is typed as the Protocol, and the function body simply calls shape.area(), trusting that whatever object it's given actually has that method. describe(Square(4)) works correctly and prints "Area is 16" precisely because this is STRUCTURAL typing, per the chapter's own explanation: Square satisfies HasArea purely by having a matching area() method that takes no extra arguments and returns a number, with no inheritance relationship between them needed at all — the same "formalized duck typing" the chapter's Car/Honker example demonstrated, just applied to Course 2's own Square class instead of a car horn.