Possible PEP: Improve classmethod/staticmethod syntax

Andrew Bennetts andrew-pythonlist at puzzling.org
Wed Jun 4 00:54:27 EDT 2003


On Wed, Jun 04, 2003 at 12:18:51AM -0400, Lulu of the Lotus-Eaters wrote:
> 
> The idea here is that it is possible to achieve something akin to what
> metaclasses do.  I don't think staticmethod() or classmethod() could
> themselves be written in pure Python rather than as C extensions (well,
> maybe).  But you could also write your own function, and use it in a
> metaclass-like way, e.g.:

They certainly can be written in pure Python!

You simply need to use descriptors; I wrote a pure Python staticmethod as
part of a talk I gave to my local PIG a few months ago about new features in
Python 2.2:

    http://pig.slug.org.au/talks/py2.2/slides.html

(Apologies for magicpoint's horrendous HTML conversion)

A more recent, and considerably more in-depth, discussion of descriptors was
recently posted to the announce list by Raymond Hettinger:

    http://users.rcn.com/python/download/Descriptor.htm

-Andrew.
 





More information about the Python-list mailing list