Bugs item #1327110, was opened at 2005-10-14 21:25
Message generated for change (Comment added) made by mwh
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1327110&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: Python 2.4
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Yusuke Shinyama (euske)
Assigned to: Michael Hudson (mwh)
Summary: wrong TypeError traceback in generator expressions

Initial Comment:
In the following session, the TypeError traceback of '
'.join( foo(i) for i in range(10) ) is wrong. The cause
is not because of being a generator, but of its
manually created exception.
--------------------------
Python 2.4.2 (#1, Oct 14 2005, 16:08:57)
[GCC 3.3.6 (Gentoo 3.3.6, ssp-3.3.6-1.0, pie-8.7.8)] on
linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> def foo(x): raise TypeError('foo!')
...
>>> def bar(x): raise ValueError('bar!')
...
>>> ' '.join( foo(i) for i in range(10) )
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: sequence expected, generator found
>>> ' '.join( bar(i) for i in range(10) )
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 1, in <generator expression>
  File "<stdin>", line 1, in bar
ValueError: bar!


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

>Comment By: Michael Hudson (mwh)
Date: 2005-10-21 12:46

Message:
Logged In: YES 
user_id=6656

Ok, this is checked in as:

Objects/stringobject.c revision 2.235
Objects/unicodeobject.c revision 2.235
Lib/test/test_string.py revision 1.28
Lib/test/string_tests.py revision 1.46

Thanks for the report.

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

Comment By: Michael Hudson (mwh)
Date: 2005-10-16 15:28

Message:
Logged In: YES 
user_id=6656

Agreed.

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

Comment By: Raymond Hettinger (rhettinger)
Date: 2005-10-16 15:24

Message:
Logged In: YES 
user_id=80475

I don't think this should be backported.

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

Comment By: Michael Hudson (mwh)
Date: 2005-10-16 13:25

Message:
Logged In: YES 
user_id=6656

Oh come on, this is just a bad idea (esp so in this case; the error message 
that you get for e.g. ''.join(1) is "iteration over non-sequence" which pretty 
clear -- I think this may have improved since the introduction of the 
PySequence_Fast API).

Here's a patch (with tests) that I'll check in after Jeremy has merged the 
ast-branch unless you talk very fast :)

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

Comment By: Raymond Hettinger (rhettinger)
Date: 2005-10-14 21:57

Message:
Logged In: YES 
user_id=80475

This isn't an error -- it was a design decision.  It is not
unusual to have a situation arise in Python where a high
level routine competes with a low level routine over which
is in the best position to provide the most useful error
message.  The low level routine typically knows the
proximate cause.  The high level routine typically knows
what the user was trying to do.  

In the case of str.join(), the high level routine usually
makes the most informative error message; however, it is
sometimes off the mark.

Will revisit the design decision to see if it should be
changed.  Lowering the priority because the code is working
as designed, the error type is correct, and it is not clear
that any change is warranted.

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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1327110&group_id=5470
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to