PyCon Pune 2017

A conference on the Python programming language

Sim Zacks

@sim

Practical Metaclasses and Decorators

Submitted Nov 4, 2016

Python gives developers direct control over every stage of the OOP process. Metaclasses are the framework used in creating classes themselves and an understanding of how decorators work bring a new light on what is happening behind the scenes. These programming tools are often considered to be among the black magic tools of expert python developers. However, they are not as scary as they look.

In this talk, I will explain how metaclasses work and present some practical examples, including a minimally invasive way to add full usage/error logging to your entire application. I will also describe how decorators work and touch on descriptors.

When you leave my talk, you will have a newfound understanding of the power that metaclass programming and decorators can give you.

Outline

###Introduction
###Agenda
###Metaclasses

  • What is it
  • Why is it relevant
  • How it works
  • Building a class definition using code
    ###Decorators
  • What is a decorator
  • How decorators work
  • Examples
  • Gotchas and workarounds
    ###Tying it together
  • Example of adding minimally invasive usage logging

Speaker bio

Sim is a principal engineer at Red Hat with 20 years of python programming experience. His experience includes DevOps, CI, software development, database design and development and system administration.

Comments

{{ gettext('Login to leave a comment') }}

{{ gettext('Post a comment…') }}
{{ gettext('New comment') }}
{{ formTitle }}

{{ errorMsg }}

{{ gettext('No comments posted yet') }}

Hosted by

PyCon Pune 2017 more