PyCon UK 2022

It's Your Call(able): a tour of Python's callable (function) interface
09-16, 15:00–15:30 (Europe/London), Assembly Room

A deep dive into python functions and the callable interface. We take a tour into everything that happens on on a “def” line and when you call the resulting function. We'll also explore how to harness detailed function metadata, and how to hack the decorator pattern.


Functions are fundamental to python, and are amongst the first features of python that most users learn. We define a function with parameters, and call it arguments to create a callable object, which then returns a value.

However, there is more to this callable interface than meets the eye, and there are lots of useful and powerful things we can do with callables in python. You may have come across some of these already: (anonymous) lambda functions, the call magic method, the decorator pattern, the doc property, and modules like functools and inspect which provide detailed about functions and allow us to alter functions at runtime. The now-retired Python 3.6 release added typing annotations to this mix, and opened up a new world of metadata to use alongside your callables.

Lots of libraries, particularly web frameworks like Flask, Django, and FastAPI, and testing toolkits like pytest, use this callable interface to implement their API. As developers, understanding these advanced features of python’s callable interface is particularly useful when writing generic, automation focused code, and understanding how such prominent libraries work.

This talk gives a deep-dive into python functions, and the associated callable interface. We’ll start with a quick tour of the basics, before covering python’s more advanced callable features, and exploring some examples about how, why, and when you may wish to use these features yourself.


Is your proposal suitable for beginners? – yes

Dom is a full stack cloud software engineer based in central London. He works as an independent contractor, primarily in financial services, and is a Principal Associate at Decision Lab, a consultancy with expertise in simulation, optimisation, and machine learning. Dom's primary expertise are in Python and Javascript, graph and relational databases, and IaC in AWS using Terraform.

Dom studied at the University of Cambridge and King's College London. Outside of work, Dom is interested in languages and travelling, and holds a voluntary statutory appointment monitoring the welfare and dignity of prisoners in a challenging North London jail.