Saturday 4 p.m.–4:50 p.m.

Multimethods? In MY Python?

Lindsey Brockman

Audience level:


A benefit of using a dynamically typed language like Python is the ability to create a function that can operate on arguments of unknown types. Unfortunately, this freedom can lead to a common antipattern where the function is responsible for type-cheaking each argument before operating accordingly. This talk will explore avoiding this antipattern with multimethods.


Back in 2005, a certain someone named Guido wrote a blog post about implementing multimethods (aka multiple dispatch) in Python. Since then, a handful of multiple dispatch related packages have become available on PyPi (and surely more than a handful of arguments have been started on the topic), but as of now, nothing in the standard library enables multimethod support right out of the box.

In this talk, we’ll learn what multimethods actually are and how they can help clean up your code. In order to avoid having most of the audience whisked away by the promise of overloading in compiled languages like Java, we’ll be sure to explore some options for integrating multimethods into your Python 3 code. By the end of the session, you should be able to identify functions that could be improved by a multiple dispatch, understand how to go about refactoring your own code to incorporate those changes, and, above all else, understand that even though it might not seem pythonic right away, multimethods can help you avoid some ugly antipatterns!