[Python-Dev] Re: PEP 318 bake-off? (original) (raw)
Phillip J. Eby pje at telecommunity.com
Thu Apr 1 19:12:35 EST 2004
- Previous message: [Python-Dev] Re: PEP 318 bake-off?
- Next message: [Python-Dev] PEP 318 bake-off?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 03:47 PM 4/1/04 -0800, Guido van Rossum wrote:
> > as [rstdirective( > > arguments=(1,0,1), > > options={'class': directives.classoption}, > > content=1 > > ) > > ] def admonition(*args): > > return makeadmonition(nodes.admonition, *args) > > I suppose so, but a generic function attribute decorator > would do just as well. IOW, it doesn't have to be > "rstdirective", just "attributes" would do fine.
I like rstdirective(), because it's more specific -- it would catch mistakes earlier. E.g. if you misspelled argumnets, attributes() would have no clue about it; but rstdirective() should have specific keywords.
Yeah, that's why I wrote the example that way. Once you have an 'attributes()' decorator, it's easy to create task-specific versions of it, e.g.:
def my_decorator(foo,bar,baz): return attributes(**locals())
And of course you can have defaults, and do validation of the attributes before the return statement.
And there's an additional reason to use task-specific decorators: if you later decide that function attributes aren't as useful, or you need to change what the attributes are named, or you decide to stick all the options into an object and use only one attribute, you need only change the task-specific decorator, not all the things that call it.
- Previous message: [Python-Dev] Re: PEP 318 bake-off?
- Next message: [Python-Dev] PEP 318 bake-off?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]