What are good uses for Python3's "Function Annotations"
Posted
by agscala
on Stack Overflow
See other posts from Stack Overflow
or by agscala
Published on 2010-06-14T14:25:51Z
Indexed on
2010/06/14
14:32 UTC
Read the original article
Hit count: 187
Function Annotations: PEP-3107
I ran across a snippet of code demonstrating Python3's function annotations. The concept is simple but I can't think of why these were implemented in Python3 or any good uses for them. Perhaps SO can enlighten me?
How it works:
def foo(a: 'x', b: 5 + 6, c: list) -> max(2, 9):
... function body ...
Everything following the colon after an argument is an 'annotation', and the information following the ->
is an annotation for the function's return value.
foo.func_annotations would return a dictionary:
{'a': 'x',
'b': 11,
'c': list,
'return': 9}
What's the significance of having this available?
© Stack Overflow or respective owner