diff -r 37905786b34b Doc/tutorial/controlflow.rst --- a/Doc/tutorial/controlflow.rst Sun Apr 12 23:24:17 2015 -0500 +++ b/Doc/tutorial/controlflow.rst Mon Apr 13 12:00:06 2015 -0400 @@ -673,11 +673,8 @@ pair: function; annotations single: -> (return annotation assignment) -:ref:`Function annotations ` are completely optional, -arbitrary metadata information about user-defined functions. Neither Python -itself nor the standard library use function annotations in any way; this -section just shows the syntax. Third-party projects are free to use function -annotations for documentation, type checking, and other uses. +:ref:`Function annotations ` are completely optional metadata +information about the types used by user-defined functions. (:pep:`484`) Annotations are stored in the :attr:`__annotations__` attribute of the function as a dictionary and have no effect on any other part of the function. Parameter @@ -686,16 +683,17 @@ defined by a literal ``->``, followed by an expression, between the parameter list and the colon denoting the end of the :keyword:`def` statement. The following example has a positional argument, a keyword argument, and the return -value annotated with nonsense:: +value annotated:: ->>> def f(ham: 42, eggs: int = 'spam') -> "Nothing to see here": +>>> def f(spam: str, egg: str = 'egg') -> str: ... print("Annotations:", f.__annotations__) - ... print("Arguments:", ham, eggs) + ... print("Arguments:", spam, egg) + ... return spam + ' ' + egg ... ->>> f('wonderful') - Annotations: {'eggs': , 'return': 'Nothing to see here', 'ham': 42} - Arguments: wonderful spam - +>>> f('flying') + Annotations: {'spam': , 'return': , 'egg': } + Arguments: flying egg + 'flying egg' .. _tut-codingstyle:

AltStyle によって変換されたページ (->オリジナル) /