Message359772
https://docs.python.org/3/tutorial/controlflow.html#function-annotations
is the direct link.
As Mark said, 'ham' is a required positional-or-keyword argument.
'eggs' is an optional 'positional-or-keyword. The sentence as is is wrong, even if Robert garbled the reason. With the signature as it, the sentence should be "The following example has a required argument, an optional argument, and the return value annotated."
To make the existing sentence true, the signature could be changed to
def f(ham: str, /, *, eggs: str) -> str:
But I think this would be wrong. Annotation does not depend on how an argument is passed, but whether it has a default (making it optional). In particular, it shows that when optional, the annotation goes *before* '= default', not after. (It could have gone after: eggs = 'eggs': str.) |
|
Date |
User |
Action |
Args |
2020-01-11 00:52:47 | terry.reedy | set | recipients:
+ terry.reedy, mark.dickinson, docs@python, r0b |
2020-01-11 00:52:47 | terry.reedy | set | messageid: <1578703967.52.0.483982111405.issue39231@roundup.psfhosted.org> |
2020-01-11 00:52:47 | terry.reedy | link | issue39231 messages |
2020-01-11 00:52:47 | terry.reedy | create | |
|