[Python-3000] yes to class decorators
Steven Bethard
steven.bethard at gmail.com
Thu Nov 16 00:38:41 CET 2006
On 11/15/06, tomer filiba <tomerfiliba at gmail.com> wrote:
> i understand there's a green light for class decorators in py3k,
> so i wanted to give the issue a slight push.
If you haven't already, you should look at PEP 359, which tried to
address many of the same use-cases and was withdrawn after feedback on
python-dev:
http://www.python.org/dev/peps/pep-0359/
> def singleton(cls):
> return cls() # create the "single instance"
>
> @singleton
> class OnlyOne(object):
> pass
That would have been something like::
make singleton OnlyOne:
pass
> @staticclass
> class Eggs(objects):
> def foo():
> print "foo"
> def goo():
> print "goo"
And this would have been something like::
make namespace Eggs:
def foo():
print "foo"
def goo():
print "goo"
> ANYWAY, if we went this far already, we might as well just
> trash the __metaclass__ syntax (*) altogether.
That was one of the open issues in the PEP too.
Basically, I think that the use-cases you've given are not a great
motivation -- they weren't enough to motivate the "make" statement of
PEP 359, so they're probably not enough to motivate class decorators.
FWIW, most of the arguments against PEP 359 were along the lines of,
"well you can do that with a metaclass already, so we don't really
need any new syntax", but you may be able to get around those
arguments because the decorator syntax already exists.
STeVe
--
I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a
tiny blip on the distant coast of sanity.
--- Bucky Katt, Get Fuzzy
More information about the Python-3000
mailing list