Issue32766
Created on 2018-02-04 17:57 by John Hossbach, last changed 2022-04-11 14:58 by admin. This issue is now closed.
| Messages (2) | |||
|---|---|---|---|
| msg311612 - (view) | Author: John Hossbach (John Hossbach) | Date: 2018-02-04 17:57 | |
https://docs.python.org/3.5/tutorial/controlflow.html#function-annotations 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. |
|||
| msg311925 - (view) | Author: Terry J. Reedy (terry.reedy) * ![]() |
Date: 2018-02-10 00:51 | |
3.5 and its docs are frozen except for security patches. The 3.7 doc is identical.
The sentence refers to the def statement and perhaps should say so. It should end with 'a required argument, an optional argument, and the return value annotated'. Or maybe better, 'annotations for ... and the return value.'
In 3.6, cpython dicts became (unofficially) input ordered. In 3.7, this became official for Python dicts. The example output should be changed to what it is now. (This is an example where the change produces better output.)
Annotations: {'ham': <class 'str'>, 'eggs': <class 'str'>, 'return': <class 'str'>}
|
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:57 | admin | set | github: 76947 |
| 2021-09-02 10:27:59 | iritkatriel | set | status: open -> closed superseder: Mistaken notion in tutorial resolution: duplicate stage: resolved |
| 2018-02-10 00:51:24 | terry.reedy | set | nosy:
+ terry.reedy messages:
+ msg311925 |
| 2018-02-04 17:57:24 | John Hossbach | create | |
