Book Image

Mastering Object-oriented Python

By : Steven F. Lott, Steven F. Lott
Book Image

Mastering Object-oriented Python

By: Steven F. Lott, Steven F. Lott

Overview of this book

Table of Contents (26 chapters)
Mastering Object-oriented Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Some Preliminaries
Index

Abstract base classes


The core of the Abstract Base Class (ABC) definition is defined in a module named abc. This contains the required decorators and metaclasses to create abstractions. Other classes rely on these definitions.

In Python 3.2, the abstract base classes for collections were buried in collections. In Python 3.3, however, the abstract base classes have been split into a separate submodule named collections.abc.

We'll also look at the numbers module, because it contains ABCs for numeric types. There are abstract base classes for I/O in the io module too.

We'll focus on Python Version 3.3. The definitions will work very similarly for Python 3.2, but the import statement will change slightly to reflect the flatter library structure.

An abstract base class has a number of features, as follows:

  • Abstract means that these classes don't contain all of the method definitions required to work completely. For it to be a useful subclass, we will need to provide some method definitions.

  • Base means...