[New-bugs-announce] [issue24018] add a Generator ABC

Stefan Behnel report at bugs.python.org
Mon Apr 20 21:36:25 CEST 2015

New submission from Stefan Behnel:

Currently, CPython tends to assume that generators are always implemented by a Python function that uses the "yield" keyword. However, it is absolutely possible to implement generators as a protocol by adding send(), throw() and close() methods to an iterator.

The problem is that these will usually be rejected by code that needs to distinguish generators from other input, e.g. in asyncio, as this code will commonly do a type check against types.GeneratorType. Instead, it should check for the expected protocol. The best way to achieve this is to extend the existing ABCs with a Generator ABC that external generator implementations can register on.

Related to issue 24004 (asyncio). Asyncio could provide a backport copy of this for older Python versions.

I assume this is considered a new feature that cannot be added to 3.4 anymore?

components: Library (Lib)
files: generator_abc.patch
keywords: patch
messages: 241675
nosy: gvanrossum, haypo, scoder, yselivanov
priority: normal
severity: normal
status: open
title: add a Generator ABC
type: enhancement
versions: Python 3.5
Added file: http://bugs.python.org/file39146/generator_abc.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list