[Python-3000] Draft pre-PEP: function annotations (original) (raw)
Stefan Behnel behnel_ml at gkec.informatik.tu-darmstadt.de
Thu Aug 10 15:00:30 CEST 2006
- Previous message: [Python-3000] Draft pre-PEP: function annotations
- Next message: [Python-3000] Draft pre-PEP: function annotations
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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: @typeannotate("This is a filename passed as string", filename = str) @typeannotate(source = str) def compile(source, filename, mode): ... or, more explicitly: @argdocstring(filename = "This is a filename passed as string") @argtype(filename = str) @argtype(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
- Previous message: [Python-3000] Draft pre-PEP: function annotations
- Next message: [Python-3000] Draft pre-PEP: function annotations
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]