[Python-3000] PEP 3107 - Function Annotations
Guido van Rossum
guido at python.org
Thu Dec 28 02:31:55 CET 2006
I just noticed that PEP 3107 has quietly been checked in. Thanks
Collin and Tony!
After skimming it, I have one observation: the grammar in the PEP
doesn't match that implemented by Tony's patch. The difference is only
apparent for tuple-unpacking parameters (e.g. b and c in "def foo(a,
(b, c), d): pass"). The PEP supports this syntax:
def foo((a, b): "something"):
while the patch supports this instead:
def foo((a: "something", b: "something_else")):
(I have to say that I like the patch version better. :-)
I also note that the PEP uses foo.__signature__.annotations to access
the annotations dict, while the patch uses foo.func_annotations. This
is reasonable since we don't have the __signature__ API yet (it's PEP
362, but I don't know its status).
Finally, the PEP uses Number, Mapping and Sequence as example
annotations. I'd rather not use those since they could incorrectly
convey the notion that annotations imply type checking semantics,
which thety don't (at least not without some kind of decorator).
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000