classification
Title: typing.Generator shorthand
Type: enhancement Stage: resolved
Components: Documentation Versions:
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Dima.Tisnek, benjamin.peterson, docs@python, levkivskyi, serhiy.storchaka
Priority: normal Keywords:

Created on 2019-10-10 01:39 by Dima.Tisnek, last changed 2019-10-12 03:15 by Dima.Tisnek. This issue is now closed.

Messages (7)
msg354307 - (view) Author: Dima Tisnek (Dima.Tisnek) * Date: 2019-10-10 01:39
Currently to annotate a generator, something like `Generator[str, None, None]` is required. Which is a bit confusing and verbose.

Can we allow shorthand, like `Generator[str]` for simple cases?

I'm not entirely certain what the semantics ought to be...
Maybe Generator[t1, t2=Any, t3=None] ?
msg354308 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2019-10-10 01:41
Is Iterator[Whatever] not sufficient for you?
msg354310 - (view) Author: Dima Tisnek (Dima.Tisnek) * Date: 2019-10-10 02:40
Actually yes it is sufficient.

I don't know why I didn't think of that!
Perhaps some note in the docs could help other lost children of Python :P
msg354482 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2019-10-11 18:26
If you would like to propose a doc fix, then please go ahead and make a PR.
msg354483 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-10-11 18:29
It is already documented, with examples. I do not think the documentation can be made better.
msg354484 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2019-10-11 18:34
Actually Serhiy is right, I just checked and found this sentence:
```
Alternatively, annotate your generator as having a return type of either Iterable[YieldType] or Iterator[YieldType]
```
msg354516 - (view) Author: Dima Tisnek (Dima.Tisnek) * Date: 2019-10-12 03:15
Clearly my attention span does not exceed 5 paragraphs, so sorry!
History
Date User Action Args
2019-10-12 03:15:55Dima.Tisneksetmessages: + msg354516
2019-10-11 18:34:45levkivskyisetstatus: open -> closed
resolution: works for me
messages: + msg354484

stage: resolved
2019-10-11 18:29:49serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg354483
2019-10-11 18:26:28levkivskyisetassignee: docs@python

components: + Documentation, - Library (Lib)
nosy: + docs@python
2019-10-11 18:26:18levkivskyisetmessages: + msg354482
2019-10-11 18:23:50levkivskyisetnosy: + levkivskyi
2019-10-10 02:40:05Dima.Tisneksetmessages: + msg354310
2019-10-10 01:41:48benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg354308
2019-10-10 01:39:01Dima.Tisnekcreate