This seems like something that could reasonably be added to Py2.6. Raymond
Raymond Hettinger wrote:
This seems like something that could reasonably be added to Py2.6.
+1 from me PEP 3107 (function annotation), PEP 3104 (nonlocal) and PEP 3132 (extended iterable unpacking: a, *b = 1,2,3) are IMHO other useful feature for 2.6. nonlocal would require a __future__ import. Christian
Christian Heimes schrieb:
PEP 3107 (function annotation), PEP 3104 (nonlocal) and PEP 3132 (extended iterable unpacking: a, *b = 1,2,3) are IMHO other useful feature for 2.6. nonlocal would require a __future__ import.
I'm planning to work on PEP 3107 (function annotations) after I have finished backporting PEP 3102 (keyword-only arguments) (issue1745). Could someone with access rights update the spreadsheet so there won't be duplicated efforts? http://spreadsheets.google.com/pub?key=pCKY4oaXnT81FrGo3ShGHGg&gid=2 Robin Stocker
Robin Stocker wrote:
I'm planning to work on PEP 3107 (function annotations) after I have finished backporting PEP 3102 (keyword-only arguments) (issue1745).
Thanks! I've backported class decorators: http://bugs.python.org/issue1759 Could somebody with more knowledge about grammer and ASDL check it out, please? Christian
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 "<stdin>", line 1, in <module> 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
Eli Courtwright wrote:
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?
You can't modify the attributes of an instance method. You have to modify the attribute of the function object.
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.
No, you don't. You have to retrieve the function object from the instance method object. The example should shed some light on the problem:
class Root(object): ... def index(self): ... return "Hello World!" ... print type(index) ... index.exposed = True ... <type 'function'> type(Root.index) <type 'instancemethod'> Root.index.exposed True Root.index.exposed = False Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'instancemethod' object has no attribute 'exposed' Root.index.im_func <function index at 0x8354e64> Root.index.im_func.exposed = False Root.index.exposed False
Christian
Christian, Thanks for the example; I'm sorry that I didn't read the docs carefully enough to realize that I could extract the original function and set the attribute on that. - Eli On Jan 8, 2008 11:49 AM, Christian Heimes <lists@cheimes.de> wrote:
The example should shed some light on the problem:
...
Root.index.im_func.exposed = False Root.index.exposed False
participants (4)
-
Christian Heimes -
Eli Courtwright -
Raymond Hettinger -
Robin Stocker