[New-bugs-announce] [issue13595] Weird behavior with generators with self-referencing output.

Pyry Pakkanen report at bugs.python.org
Tue Dec 13 20:25:40 CET 2011


New submission from Pyry Pakkanen <frostburn at suomi24.fi>:

The following self-referencing generator has incorrect output:

def ab_combinations():
    #'', 'a', 'b', 'aa', 'ab', 'ba', 'bb', 'aaa', ...
    def _deferred_output():
        yield ""
        tees = tee(output)

        #This definition works fine: '', 'a', 'b', 'aa', 'ab', 'ba', ...
        l = [(item+"a" for item in tees[0]), (item+"b" for item in tees[1])]

        #This definition results in: '', 'b', 'b', 'bb', 'bb', 'bb', ...
        #l = [(item+label for item in t) for t, label in zip(tees,"ab")]
        
        while True:
            for g in l:
                yield next(g)

    result, output = tee(_deferred_output())
    return result

----------
messages: 149403
nosy: PyryP
priority: normal
severity: normal
status: open
title: Weird behavior with generators with self-referencing output.
type: behavior
versions: Python 2.7, Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13595>
_______________________________________


More information about the New-bugs-announce mailing list