A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/python/typing/issues/975 below:

Allow Generator type annotation to have one argument. · Issue #975 · python/typing · GitHub

To annotate a generator yielding an int, it’s
--> Generator[int, None, None]

That's really quite ugly.

It should be Generator[int]

Passing None does not fit the rest of Python where arguments are optional. Also in the rest of Python, the common cases are the default. This makes an unlikely case most prominent over the far more common case. It’s Python’s job to provide syntactic sugar to deal with the low-level details, not the user. This looks more like C.

https://docs.python.org/3/library/typing.html#typing.Generator

“Alternatively, annotate your generator as having a return type of either Iterable[YieldType] or Iterator[YieldType]”

Yes a generator is an iterator and an iterator is an iterable but then why not set everything as Any? Are we annotating the types or not? That advice makes a mockery of the whole idea. Makes Python harder to teach for no good reason. "Put the type the function returns, unless it's a generator then do this..."

Several people have pointed this out before, their bugs got closed without explanation. One suggested making a bug here, so this is it. Enjoy.

python/mypy#4221
https://bugs.python.org/issue31700

I'm hoping this bug gets closed because someone's already fixed it in a development version 😎.

Cheers.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4