The abc module
standardbeginnerabc is the standard-library module behind Python's abstract base classes — it supplies the ABC base class and the @abstractmethod decorator that together stop a class from being instantiated until it fills in every required method.
Think of it as
abc is the module a form-template system is built from — ABCMeta is the printer that refuses to hand out a blank form with required fields still missing. ABC and @abstractmethod are the two pieces most code actually reaches for; ABCMeta is the machinery underneath both, rarely used directly.
What we're doing: Define an abstract base class with one required method, then show that Python itself refuses to instantiate it directly.
- 3
- class Shape(ABC): opts into abc's enforcement — without this, @abstractmethod below would be decorative only.
- 4
- @abstractmethod marks area as required — any subclass that skips it cannot be instantiated either.
- 9
- Circle defines area, so it satisfies the requirement and can be instantiated normally.
12.56636
Traceback (most recent call last):
...
TypeError: Can't instantiate abstract class Shape without an implementation for abstract method 'area'Why this works: Circle(2).area() works because Circle provides a concrete area, satisfying the one requirement Shape declared. Shape() itself fails at the instantiation step — before __init__ even runs — because Python's ABCMeta machinery checks for unimplemented abstract methods and refuses to build the object at all, rather than letting it fail later when area() is actually called.
Forgetting to inherit from ABC and expecting @abstractmethod to still enforce anything
Wrong
Better
What you see: Shape() succeeds silently — @abstractmethod alone does nothing; the check lives in ABCMeta, which only runs for classes that use it.
Why: @abstractmethod just sets an attribute (__isabstractmethod__ = True) on the function — it is ABCMeta, inherited via ABC, that actually scans a class for any method still carrying that flag and blocks instantiation. Without ABC in the base classes, the decorator is inert.
What abc actually exports
Together
Remember: ABC (not ABCMeta) is what actually enforces @abstractmethod — inheriting from ABC is what makes an unimplemented abstract method block instantiation.
See also: abstract base classes · abstraction · inheritance

