@@ -673,11 +673,9 @@ Function Annotations
673673 pair: function; annotations
674674 single: -> (return annotation assignment)
675675
676- :ref: `Function annotations <function >` are completely optional,
677- arbitrary metadata information about user-defined functions. Neither Python
678- itself nor the standard library use function annotations in any way; this
679- section just shows the syntax. Third-party projects are free to use function
680- annotations for documentation, type checking, and other uses.
676+ :ref: `Function annotations <function >` are completely optional metadata
677+ information about the types used by user-defined functions (see :pep: `484 `
678+ for more information).
681679
682680Annotations are stored in the :attr: `__annotations__ ` attribute of the function
683681as a dictionary and have no effect on any other part of the function. Parameter
@@ -686,16 +684,17 @@ expression evaluating to the value of the annotation. Return annotations are
686684defined by a literal ``-> ``, followed by an expression, between the parameter
687685list and the colon denoting the end of the :keyword: `def ` statement. The
688686following example has a positional argument, a keyword argument, and the return
689- value annotated with nonsense ::
687+ value annotated::
690688
691- >>> def f(ham: 42 , eggs: int = 'spam ') -> "Nothing to see here" :
689+ >>> def f(ham: str , eggs: str = 'eggs ') -> str :
692690 ... print("Annotations:", f.__annotations__)
693691 ... print("Arguments:", ham, eggs)
692+ ... return ham + ' and ' + eggs
694693 ...
695- >>> f('wonderful ')
696- Annotations: {'eggs ': <class 'int '>, 'return': 'Nothing to see here' , 'ham ': 42 }
697- Arguments: wonderful spam
698-
694+ >>> f('spam ')
695+ Annotations: {'ham ': <class 'str '>, 'return': <class 'str'> , 'eggs ': <class 'str'> }
696+ Arguments: spam eggs
697+ 'spam and eggs'
699698
700699.. _tut-codingstyle :
701700
0 commit comments