PythonAsia 2026

PythonAsia 2026

Multiple and Predicative Dispatch
2026-03-22 , Teresa Yuchengco Auditorium (Main Hall)

Complex flow control decisions can be elegantly expressed as dispatch by function signatures.


One of the fundamental operations in structured programming is "dispatching" operations to relevant blocks of code, based on some criteria a program can determine. Most Python programmers are familiar with object-oriented programming in which a call to instance.method() will examine the class of instance to determine the specific code called. This uses something called an MRO (method resolution order). However, OOP is far from the only possible dispatch strategy.

One alternative approach is something called multiple dispatch, also known as multimethods. Under this approach, the types (and number) of the arguments to a function rather than its inheritance tree determine which code is utilized to implement a function or method call. Function overloading in languages like C++, Java, Julia, or Fortran, are limited examples of multiple dispatch; Python itself also offers a limited version with its @singledispatch decorator.

Under true multiple dispatch, the types of ALL the arguments to a function are considered in the decision of which code to execute. Many people have implemented Python modules to support full multiple dispatch, dating from the early 2000s. Those are all nice tools, varying mostly in syntactic approaches and specific resolution rules.

Predicative dispatch is an idea has been implemented less widely. We can create several versions of a function that vary not only in the data types passed as arguments, but also by properties these arguments might have. In a simple example, we might have code paths for integer arguments, but also different paths depending on whether these integers are positive or negative.

Notes: This is a refinement of a talk delivered at PyCon Africa 2025. Since then, the API has been fleshed out and additional tests and documentation created for gnosis-dispatch.


Category: Core Python/Advanced Language Features Audience Level: Intermediate

David is Principal Software and Security Architect of Service Employees International Union, one of the largest and most progressive unions in the United States. He served as a Director of the Python Software Foundation and chair of a number of its committees for many years. He created the data science training program for Anaconda Inc. and was a senior trainer for them. Before that, he worked for 8 years with D. E. Shaw Research, who built the world's fastest, highly-specialized supercomputer for performing molecular dynamics.

David's columns, Charming Python and XML Matters, written in the 2000s, were the most widely read articles in the Python world. He has written 7 books in Python or adjacent topics for Manning, Packt, O'Reilly, Addison-Wesley, and Lulu Press, and has given keynote addresses at numerous international programming conferences.