[Python-3000] PEP Draft: Class Decorators

Jack Diederich jackdied at jackdied.com
Wed Feb 28 21:52:12 CET 2007

Greetings from PyCon!

I read hundreds of emails in the dozens of threads about class decorators and
there was surprisingly little content (most of the arguments were about syntax
which is no longer up for debate). As a result this PEP is quite plain.

If any IronPython or Jython folks could throw in their two bits it would be

Title: Class Decorators
Version: 1
Last-Modified: 28-Feb-2007
Authors: Jack Diederich
Implementation: SF#1671208
Status: Draft
Type: Standards Track
Created: 26-Feb-2007


Extending the decorator syntax to allow the decoration of classes.


Allowing classes to be decorated serves many of the same purposes as
the ability to decorate functions.  Decorators move factory registration
and class manipulation to the top of the class definition instead of the
current alternate methods of post-processing or the action-at-a-distance
of metaclasses.

    import myfactory
    class MyClass:

History and Implementation

Class decorators were originally proposed in PEP318 [1]_ and were rejected
by Guido [2]_ for lack of use cases.  Two years later he saw a use case
he liked and gave the go-ahead for a PEP and patch [3]_.

The current patch is loosely based on a pre-2.4 patch [4]_ and updated to
use the new AST.

Grammar/Grammar is changed from

   funcdef: [decorators] 'def' NAME parameters ['->' test] ':' suite


    decorated_thing: decorators (classdef | funcdef)
    funcdef: 'def' NAME parameters ['->' test] ':' suite

If you enjoyed this PEP you might also enjoy:

.. [1] PEP 318, "Decorators for Functions and Methods"

.. [2] Class decorators rejection

.. [3] Class decorator go-ahead

.. [4] 2.4 class decorator patch

.. [5] 3.x class decorator patch

More information about the Python-3000 mailing list