Contribute Media
A thank you to everyone who makes this possible: Read More

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

Translations: en

Description

Graham Dumpleton https://2016.pycon-au.org/schedule/18/view_talk 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.

Details

Improve this page