Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
3f103462
Commit
3f103462
authored
Apr 13, 2015
by
Zachary Ware
Browse files
Options
Browse Files
Download
Plain Diff
Closes #23932: Merge with 3.4
parents
0b1e4f14
f3b990e4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
11 deletions
+10
-11
Doc/tutorial/controlflow.rst
Doc/tutorial/controlflow.rst
+10
-11
No files found.
Doc/tutorial/controlflow.rst
View file @
3f103462
...
...
@@ -673,11 +673,9 @@ Function Annotations
pair: function; annotations
single: -> (return annotation assignment)
:ref:`Function annotations <function>` 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 <function>` are completely optional metadata
information about the types used by user-defined functions (see :pep:`484`
for more information).
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 +684,17 @@ expression evaluating to the value of the annotation. Return annotations are
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(ham:
str, eggs: str = 'eggs') -> str
:
... print("Annotations:", f.__annotations__)
... print("Arguments:", ham, eggs)
... return ham + ' and ' + eggs
...
>>> f('
wonderful
')
Annotations: {'
eggs': <class 'int'>, 'return': 'Nothing to see here', 'ham': 42
}
Arguments:
wonderful spam
>>> f('
spam
')
Annotations: {'
ham': <class 'str'>, 'return': <class 'str'>, 'eggs': <class 'str'>
}
Arguments:
spam eggs
'spam and eggs'
.. _tut-codingstyle:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment