Preface
- Errata and Suggestions
- Conventions Used in This Book
Welcome!
Prerequisites
- A functioning Python 3.5+ runtime
- Experience with concepts from the previous books
The Road Goes On Forever
Chapter 1 - Advanced Flow Control
elseclauses on loops- An alternative to loop
elseclauses - The try..except..else construct
- Emulating switch
- Dispatching on Type
- Summary
Chapter 2 - Byte Oriented Programming
- Bitwise operators
- The
bytestype in depth - The mutable
bytearraysequence - Interpreting byte streams with the
structmodule - Memory Views
- Memory-mapped files
- Summary
Chapter 3 - Object Internals and Custom Attributes
- How are Python objects stored?
- Using
vars()to access__dict__ - Overriding
__getattribute__() - Special methods which bypass
__getattribute__() - Where are the methods?
- Slots
- Summary
Chapter 4 - Descriptors
- A review of properties
- Unravelling the property function
- Implementing a descriptor
- Retrieving descriptors on classes
- Data versus non-data descriptors
- Summary
Chapter 5 - Instance Creation
- Instance Creation
- Customising allocation
- Summary
Chapter 6 - Metaclasses
- The class of class objects
- Class allocation and initialisation
- Passing additional arguments to the metaclass
- Metaclass methods and visibility
- Fine-grained instantiation control with metaclass
__call__() - Practical metaclass examples
- Metaclasses and Inheritance
- Summary
Chapter 7 - Class decorators
- A first class decorator
- Enforcing constraints with a class decorator
- Enforcing constraints for properties
- Chaining class decorators
- Summary
Chapter 8 - Abstract Base Classes
- What is an abstract base-class?
- Why are abstract base-classes useful?
- What about duck typing?
- Abstract base-classes in Python
- Defining subclasses with
__subclasscheck__() - Non-transitivity of subclass relationships
- Method resolution and virtual base-classes
- Library support for abstract base-classes
- Combining abstractmethod with other decorators
- Propagating abstractness through descriptors
- Fixing our
@invariantclass decorator with ABCs - Summary