[Python-Dev] Backport PEP 3129: Class Decorators (original) (raw)
Eli Courtwright eli at courtwright.org
Tue Jan 8 17:42:07 CET 2008
- Previous message: [Python-Dev] Backport PEP 3129: Class Decorators
- Next message: [Python-Dev] Backport PEP 3129: Class Decorators
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Since we're talking about class decorators, I have a question about function and instancemethod objects. The following code works
class Root(object): def index(self): return "Hello World!" index.exposed = True
but this code
class Root(object): def index(self): return "Hello World!" index.exposed = True
gives the following exception
Traceback (most recent call last): File "", line 1, in AttributeError: 'instancemethod' object has no attribute 'exposed'
I can tell that instancemethods can't have attributes added to them outside of their class definition. Is this part of the Python language spec, or just an implementation detail of CPython?
I bring this up here because it makes writing certain class decorators much more annoying. For example, if I want to write a class decorator that will set "exposed=True" for every method of a class, I must resort to shenanigans.
- Eli -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-dev/attachments/20080108/aafbc326/attachment.htm
- Previous message: [Python-Dev] Backport PEP 3129: Class Decorators
- Next message: [Python-Dev] Backport PEP 3129: Class Decorators
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]