[Python-3000] Draft pre-PEP: function annotations
Stefan Behnel
behnel_ml at gkec.informatik.tu-darmstadt.de
Thu Aug 10 15:00:30 CEST 2006
Stefan Behnel wrote:
> Collin Winter wrote:
>> def compile(source: "something compilable",
>> filename: "where the compilable thing comes from",
>> mode: "is this a single statement or a suite?"):
>> ...
>>
>> def sum(*vargs: Number) -> Number:
>> ...
>
> Admittedly, I'm not so much in the "Spring stew" discussion, but I'm not a big
> fan of cluttering up my function signature with "make them short to make them
> fit" comments.
>
> What would be wrong in adding a standard decorator for this purpose? Something
> like:
>
> @type_annotate("This is a filename passed as string", filename = str)
> @type_annotate(source = str)
> def compile(source, filename, mode):
> ...
>
> or, more explicitly:
>
> @arg_docstring(filename = "This is a filename passed as string")
> @arg_type(filename = str)
> @arg_type(source = str)
> def compile(source, filename, mode):
> ...
Ah, never mind, that only applies to docstrings. The type annotation would not
be available to the compiler...
So, it would be a good idea to split the two: docstrings and types. Where a
decorator provides a readable (and extensible) solution for the first, type
annotations should be part of the signature IMHO.
Stefan
More information about the Python-3000
mailing list