[Python-Dev] Re: def fn (args) [dec,dec]: (original) (raw)
Michael Walter michael.walter at gmail.com
Wed Aug 11 04:14:30 CEST 2004
- Previous message: [Python-Dev] Re: def fn (args) [dec,dec]:
- Next message: [Python-Dev] status of statistics.py?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Let's see how we could reduce that in a (hypothetical) optionally-typed Python, supposed that we use meaningful variable+classnames (thus usually avoiding the need for parameter descriptions):
@precondition(some_validator, lastarg) @postcondition(rv_validator) @classmethod def someMethod(klass, anarg : aClass, otharg : othClass, lastarg : lastClass) -> rClass:
foo
By moving preconditions into the type (which is often possible -- in the other case we often don't want to expose the precondition publically, anyway, at least in my limited experience), we can reduce this some more:
@postcondition(rv_validator) @classmethod def someMethod(klass, anarg : aClass, otharg : othClass, lastarg : lastClassSubType) -> rClass:
foo
The only remaining question would be whether the postcondition should be revealed in the method's "interface" (which I consider the decorations to be part of) - I would also think that usually this isn't the case (question: would you put them into the code in the form of asserts instead? or use the old someMethod = postconditioned(someMethod, rv_validator) syntax?).
I'm pretty sure I've made too many assumptions for too many people (and I don't really see the point of my post yet), but oh well :)
Cheers, Michael
On Wed, 11 Aug 2004 13:57:03 +1200, Greg Ewing <greg at cosc.canterbury.ac.nz> wrote:
> > Perhaps someone can post some real-life use cases written with this > > syntax, > > well, how about this: > > def someMethod(klass, anarg, otharg, lastarg): > """ > Summary. > > Long description that explains the details about someMethod. > Aliquam venenatis orci in risus. Nunc ornare aliquam
I was hoping for some real live code, e.g. an excerpt from PyObjC. This is still a made-up example. > @param(anarg, aClass, 'desc of anarg') > @param(otharg, othClass, 'desc of otharg') > @param(lastarg, lastClass, "longer desc of lastarg because it's special") > @return(rClass, 'return value description') > @precondition(somevalidator, lastarg) > @postcondition(rvvalidator) > @classmethod > def someMethod(klass, anarg, otharg, lastarg): > """ > Summary. And this looks awful - the method name is almost completely lost under the deluge of preceding junk!
Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | greg at cosc.canterbury.ac.nz +--------------------------------------+
Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/michael.walter%40gmail.com
- Previous message: [Python-Dev] Re: def fn (args) [dec,dec]:
- Next message: [Python-Dev] status of statistics.py?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]