[ python-Bugs-970459 ] Generators produce wrong exception

SourceForge.net noreply at sourceforge.net
Sat Jun 12 04:15:01 EDT 2004


Bugs item #970459, was opened at 2004-06-10 16:58
Message generated for change (Comment added) made by anders_lehmann
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=970459&group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Anders Lehmann (anders_lehmann)
Assigned to: Nobody/Anonymous (nobody)
Summary: Generators produce wrong exception

Initial Comment:
The following script :

def f():
    yield "%s" %('Et','to')
    
for i in f(): print i

will produce the following traceback in Python 2.3.4

Traceback (most recent call last):
  File "python_generator_bug.py", line 6, in ?
    b+=f()
TypeError: argument to += must be iterable

Where I would expect a:

TypeError : not all arguments converted during string 
formatting.

----------------------------------------------------------------------

>Comment By: Anders Lehmann (anders_lehmann)
Date: 2004-06-12 10:15

Message:
Logged In: YES 
user_id=1060856

I am sorry  that I overoptimized the script that should 
demonstrate the error.

The problem was discovered with the :
b=[]
b+=f()

I find it very confusing that the reported error is that the 
function is not iterable ( which isnt due to a format error ).

When the generator is more complex than the example the 
exception doesn't help in locating the bug.

But if Tim thinks it is the correct behaviour I will close the bug.


----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2004-06-12 09:03

Message:
Logged In: YES 
user_id=80475

Ander, if this resolves your issue, please close this bug.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2004-06-10 17:38

Message:
Logged In: YES 
user_id=31435

The script you gave does produce the message you expect:

>>> def f():
...     yield "%s" %('Et','to')
...
>>> for i in f(): print i
...
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 2, in f
TypeError: not all arguments converted during string 
formatting
>>>

The traceback you gave contains the line

b+=f()

which doesn't appear in the script you gave.  If the script 
you *actually* ran had, for example,

>>> b = []
>>> b += f()

Then

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: argument to += must be iterable
>>>

is an appropriate exception.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=970459&group_id=5470



More information about the Python-bugs-list mailing list