On 03/30/04 16:21, Guido van Rossum wrote: >>Another possibility that has been suggested is >> >>[decorator] >>def func(arg, arg): > > And one that I currently favor. I'm out of bandwidth to participate > on a msg-by-msg basis, but perhaps folks can see if they can come to > terms with this solution? +1. We had a short email exchange about this a while ago. I'm glad it's back on the table. It's elegant, and the decorations people are already using will become more apparent than they are today. This is important to me because decorators need to be very visible. One class I frequently use (SimpleVocabulary in Zope 3) drove me crazy at first until I understood the pattern the author had used. The constructor takes two strange arguments, and for quite a while I couldn't figure out just what it wanted. Finally, I noticed that the class has several classmethods, and they all call the constructor. The author intended users to call the classmethods, not the constructor, but it was hard to notice any classmethods since the word "classmethod" was buried below the function body. Using "cls" as a first argument didn't help, since I've practically trained my eyes to ignore the first argument. Zope has experimented with several ways of decorating methods with security declarations. Here are some of the variations attempted so far: class Foo: __ac_permissions__ = (('bar', 'View management screens'),) def bar(self): pass InitializeClass(Foo) # Finds __ac_permissions__ and changes methods class Foo: bar__roles__ = PermissionRole('View management screens') def bar(self): pass class Foo: security = ClassSecurityInfo() security.declareProtected('View management screens', 'bar') def bar(self): pass InitializeClass(Foo) # Finds a ClassSecurityInfo and calls it These are all bad enough that Zope 3 has chosen to make no such declarations at all in Python code, putting them in XML instead. That may be the right choice for Zope 3, but surely other Python developers are running into similar needs on their own projects. They shouldn't have to go through this pain. They should be able to start with something clean like this: class Foo: [protected('View management screens')] def bar(self): pass Shane
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4