Bugs item #1327110, was opened at 2005-10-14 15:25 Message generated for change (Comment added) made by rhettinger 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: Open Resolution: None >Priority: 1 Submitted By: Yusuke Shinyama (euske) >Assigned to: Raymond Hettinger (rhettinger) 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: Raymond Hettinger (rhettinger) Date: 2005-10-14 15: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