💡 Common Mistake:Instantiation blocked until all abstract methods exist ➔ Generic[T] parameterises by element type (Stack[int]) for consistent checking without per-type duplication.
⚖️ Core Decision Matrix
Abstract method
Concrete method
Body?
❌ (...)
✅
Decorator
@abstractmethod
none
Subclass must override?
✅
optional
Blocks instantiation?
✅ until implemented
❌
When It Flips: three ways to satisfy an interface — ABC (nominal, enforced, allows shared code), pure interface (Java interface, contract only), duck typing (structural, flexible but unchecked until call time). ABCs trade flexibility for early, checked guarantees.
📊 Exam Execution Trace
Manual Execution Trace
Which methods go where:
Step / State
Method
Depends on
Placement
0 (Init)
—
—
—
1
is_empty/__len__
shared length
concrete (base)
2
clear
shared state
concrete (base)
3
push/pop/peek
backing storage
abstract
4
is_full
storage capacity
abstract
Applied Exercise
Problem: Show how the ABC enforces the contract at instantiation.
Derivation Proof / Hand-Calculation Walkthrough: