[docs] [issue32766] 4.7.7. Function Annotations

John Hossbach report at bugs.python.org
Sun Feb 4 12:57:24 EST 2018

New submission from John Hossbach <john.hossbach at gmail.com>:


The end of the first paragraph states, "The following example has a positional argument, a keyword argument, and the return value annotated:"

However, the only function call is f('spam') which has a single positional argument.

I believe the author was referencing the output of print("Annotations:", f.__annotations__) which was:
Annotations: {'ham': <class 'str'>, 'return': <class 'str'>, 'eggs': <class 'str'>}

and then confused that with 4.7.2. Keyword Arguments (https://docs.python.org/3.5/tutorial/controlflow.html#keyword-arguments) where it points out that keyword arguments follow positional arguments.  However, the difference between identifying a positional argument vs keyword argument is done at the function CALL, not the function DEFINITION since any argument can be both positional or keyword, depending on how it is referenced.

Moreover, the last sentence in 4.7.2. Keyword Arguments, points out that the order of unsorted sequences is undefined, which would then explain why 'return' appears in the middle here instead of at the end.

assignee: docs at python
components: Documentation
messages: 311612
nosy: John Hossbach, docs at python
priority: normal
severity: normal
status: open
title: 4.7.7. Function Annotations
versions: Python 3.5

Python tracker <report at bugs.python.org>

More information about the docs mailing list