Friday 1:30 p.m.–2:10 p.m.

Hear no evil, see no evil, patch no evil: Or, how to monkey-patch safely.

Graham Dumpleton

Audience level:
Intermediate

Description

Monkey patching has come to have a reputation of being somewhat evil. In this talk you will learn what monkey patching is all about and whether its reputation as being evil is truly justified.

Abstract

Python is a dynamic programming language and has a strong tradition of adhering to a programming style called duck-typing. This means that it is possible to easily modify an application's code while it is running. One might wish to do this for various reasons, including enhancing the functionality of code, correcting errant behaviour, or adding instrumentation or debugging code.

Making such code modifications can be tricky though and not done correctly can potentially interfere with the operation of the original code, through destroying introspection abilities, not honouring the duck-typing mantra or due to being applied at the wrong time.

If you do need to do monkey patching though, the 'wrapt' library is your friend, with its transparent object proxy wrappers and post import hook mechanism, it allows you to safely monkey patch code to modify its behaviour.

Come learn about the 'wrapt' library and the joys, but also the dangers, of monkey patching.