[Python-Dev] Class decorators (original) (raw)

Jack Diederich jack at performancedrivers.com
Wed Mar 29 19:45:06 CEST 2006


On Wed, Mar 29, 2006 at 01:11:06AM -0500, Fred L. Drake, Jr. wrote:

On Wednesday 29 March 2006 00:48, Fred L. Drake, Jr. wrote: > I think the existing usage for classes is perfectly readable. The > @-syntax works well for functions as well.

On re-reading what I wrote, I don't think I actually clarified the point I was trying to make originally. My point wasn't that I desparately need @-syntax for class decorators (I don't), or see it as inherantly superior in some way. It's much simpler than that: I just want to be able to use the same syntax for a group of use cases regardless of whether the target is a function or a class. This fits into the nice-to-have category for me, since the use case can be the same regardless of whether I'm decorating a class or a function. (I will note that when this use case applies to a function, it's usually a module-level function I'm decorating rather than a method.)

Agreed, let's not have the decorator syntax argument all over again. Once someone knows how a function decorator works they should be able to guess how a class decorator works. In my old patch[1] the grammar production for decorators was:

decorated_thing: decorators (funcdef|classdef)

Which makes sense, once you know how to decorate one thing you know how to decorate all things.

-jackdied

[1] http://python.org/sf/1007991



More information about the Python-Dev mailing list