[Python-3000] Function annotations considered obfuscatory (Re: Conventions for annotation consumers) (original) (raw)
Josiah Carlson jcarlson at uci.edu
Wed Aug 16 19:03:05 CEST 2006
- Previous message: [Python-3000] Function annotations considered obfuscatory (Re: Conventions for annotation consumers)
- Next message: [Python-3000] Function annotations considered obfuscatory (Re: Conventions for annotation consumers)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Guido van Rossum" <guido at python.org> wrote:
On 8/16/06, Jim Jewett <jimjjewett at gmail.com> wrote: > That is one reason I wonder whether all annotations/modifications have > to actually be part of the prologue, or whether they could be applied > to the Signature afterwards.
And how would that reduce the clutter? The information still has to be entered by the user, presumably with the same disambiguating tags, and some punctuation.
I'd say that pulling out annotations from the function signature, which was argued to be the most important piece of information about a function during the decorator discussion, could do at least as much to reduce clutter and increase readability and understandability, as anything else discussed with regards to the PEP so far.
To pull back out that 9 line function...
@docstring @typechecker @constrainvalues def foo(a: {'doc': "Frobnication count", 'type': Number, 'constrainvalues': range(3, 9)}, b: {'type': Number, # This can be only 4, 8 or 12 'constrainvalues': [4, 8, 12]}) -> {'type': Number}
First cleaning up the annotations to not use a dictionary:
@docstring @typechecker @constrain_values def foo(a: [doc("frobination count"), type(Number), constrain_values(range(3,9))], b: [type(Number), # This can be only 4, 8 or 12 constrain_values([4,8,12])]) -> type(Number):
Now lets pull those annotations out of the signature...
@docstring @typechecker @constrain_values @signature([doc("frobination count"), type(Number), constrain_values(range(3,9))], [type(Number), # This can be only 4, 8 or 12 constrain_values((4,8,12))], returns=type(Number)) def foo(a, b):
Ultimately the full function definition (including decorators) is just as cluttered, but now we can see that we have a function that takes two arguments, without having to scan for 'name:' . If it is necessary for somone to know what kinds of values, types, docs, etc., then they can use the documentation-producing tool that will hopefully come with their annotation consumer(s).
- Josiah
P.S. Then there is the blasphemous:
@docstring(a="frobination count") @typechecker(a=type(Number), b=type(Number)) @constrain values(a=range(3,9), b=(4,8,12), returns=type(Number)) def foo(a, b):
- Previous message: [Python-3000] Function annotations considered obfuscatory (Re: Conventions for annotation consumers)
- Next message: [Python-3000] Function annotations considered obfuscatory (Re: Conventions for annotation consumers)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]