Re: [Python-Dev] with_traceback

2007-03-07 Thread Michael Foord
Greg Ewing wrote: Michael Foord wrote: With the proposed changes, modules that do this would *continue* to work, surely ? Probably, but it might mean they were no longer thread safe. An exception caught and raised in one thread would be vulnerable to having its traceback

Re: [Python-Dev] with_traceback

2007-03-02 Thread Andrew Dalke
On 3/1/07, Guido van Rossum [EMAIL PROTECTED] wrote: Since by far the most common use case is to create the exception in the raise statement, the behavior there won't be any different than it is today; the traceback on precreated objects will be useless, but folks who precreate them for

Re: [Python-Dev] with_traceback

2007-03-02 Thread Michael Foord
Greg Ewing wrote: Michael Foord wrote: With the proposed changes, modules that do this would *continue* to work, surely ? Probably, but it might mean they were no longer thread safe. An exception caught and raised in one thread would be vulnerable to having its traceback

Re: [Python-Dev] with_traceback

2007-03-02 Thread Greg Ewing
Michael Foord wrote: Greg Ewing wrote: An exception caught and raised in one thread would be vulnerable to having its traceback clobbered by another thread raising the same instance. Right - but that would still be *no worse* than the current situation where that information isn't

Re: [Python-Dev] with_traceback

2007-03-02 Thread Michael Foord
Greg Ewing wrote: Michael Foord wrote: Greg Ewing wrote: An exception caught and raised in one thread would be vulnerable to having its traceback clobbered by another thread raising the same instance. Right - but that would still be *no worse* than the current situation

Re: [Python-Dev] with_traceback

2007-03-01 Thread Greg Ewing
James Y Knight wrote: It seems to me that a stack trace should always be attached to an exception object at creation time Um. Yes. Well, that's certainly an innovative solution... The traceback won't necessarily be *useful*, Almost completely use*less*, I would have thought. The traceback

Re: [Python-Dev] with_traceback

2007-03-01 Thread Greg Ewing
Michael Foord wrote: With the proposed changes, modules that do this would *continue* to work, surely ? Probably, but it might mean they were no longer thread safe. An exception caught and raised in one thread would be vulnerable to having its traceback clobbered by another thread raising

Re: [Python-Dev] with_traceback

2007-03-01 Thread Greg Ewing
[EMAIL PROTECTED] wrote: Perhaps the use-cases for attaching the traceback object to the exception would be better satisfied by simply having sys.exc_info() return an object with methods like Failure? I can't think of a good name for the new object type, Maybe we could call it a 'catch'

Re: [Python-Dev] with_traceback

2007-03-01 Thread Guido van Rossum
On 2/28/07, James Y Knight [EMAIL PROTECTED] wrote: On Feb 28, 2007, at 9:10 PM, Guido van Rossum wrote: I am beginning to think that there are serious problems with attaching the traceback to the exception; I really don't like the answer that pre-creating an exception is unpythonic in

Re: [Python-Dev] with_traceback

2007-03-01 Thread Guido van Rossum
On 2/28/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Wed, 28 Feb 2007 18:10:21 -0800, Guido van Rossum [EMAIL PROTECTED] wrote: I am beginning to think that there are serious problems with attaching the traceback to the exception; I really don't like the answer that pre-creating an

Re: [Python-Dev] with_traceback

2007-02-28 Thread Shane Holloway
On Feb 28, 2007, at 1:50 AM, Andrew Dalke wrote: Glyph: This seems like kind of a strange micro-optimization to have an impact on a language change discussion. Just as a reminder, my concern is that people reuse exceptions (rarely) and that the behavior of the with_exceptions()

Re: [Python-Dev] with_traceback

2007-02-28 Thread Collin Winter
On 2/26/07, Greg Ewing [EMAIL PROTECTED] wrote: Phillip J. Eby wrote: At 03:38 PM 2/26/2007 -0700, Andrew Dalke wrote: NO_END_OF_RECORD = ParserError(Cannot find end of record) Then don't do that, as it's bad style for Python 3.x. ;-) I don't like that answer. I can think of

Re: [Python-Dev] with_traceback

2007-02-28 Thread Greg Ewing
[EMAIL PROTECTED] wrote: Or modify __new__ on your particular heavily-optimized exception to have a free-list, Doing that in Python is likely to have as much overhead as creating an instance. The simple and obvious optimisation is to pre-create the instance, but we're proposing to make the

Re: [Python-Dev] with_traceback

2007-02-28 Thread Greg Ewing
Adam Olsen wrote: It sounds like we should always copy the exception given to raise, I don't like that either, for all the reasons that make it infeasible to copy an arbitrary object in a general way. -- Greg ___ Python-Dev mailing list

Re: [Python-Dev] with_traceback

2007-02-28 Thread Adam Olsen
On 2/28/07, Guido van Rossum [EMAIL PROTECTED] wrote: I am beginning to think that there are serious problems with attaching the traceback to the exception; I really don't like the answer that pre-creating an exception is unpythonic in Py3k. How plausible would it be to optimize all exception

Re: [Python-Dev] with_traceback

2007-02-28 Thread Greg Ewing
Jean-Paul Calderone wrote: And the new behavior? Every raise statement copies an exception instance, some code will create a new exception instance for each raise statement, some code will create a single exception and re-raise it repeatedly. Make that most code will create a new exception

Re: [Python-Dev] with_traceback

2007-02-28 Thread Greg Ewing
Adam Olsen wrote: How plausible would it be to optimize all exception instantiation? Perhaps use slots and a freelist for everything inheriting from BaseException and not inheriting from other builtin types? I'm not sure a free list would help much for instances of user define classes, since

Re: [Python-Dev] with_traceback

2007-02-28 Thread Adam Olsen
On 2/28/07, Greg Ewing [EMAIL PROTECTED] wrote: Adam Olsen wrote: How plausible would it be to optimize all exception instantiation? Perhaps use slots and a freelist for everything inheriting from BaseException and not inheriting from other builtin types? I'm not sure a free list would

Re: [Python-Dev] with_traceback

2007-02-28 Thread James Y Knight
On Feb 28, 2007, at 9:10 PM, Guido van Rossum wrote: I am beginning to think that there are serious problems with attaching the traceback to the exception; I really don't like the answer that pre-creating an exception is unpythonic in Py3k. I'll say up front that I haven't been paying as much

Re: [Python-Dev] with_traceback

2007-02-28 Thread Andrew Dalke
On 2/28/07, James Y Knight [EMAIL PROTECTED] wrote: It seems to me that a stack trace should always be attached to an exception object at creation time of the exception, and never at any other time. Then, if someone pre-creates an exception object, they get consistent and easily explainable

Re: [Python-Dev] with_traceback

2007-02-28 Thread Michael Foord
Andrew Dalke wrote: On 2/28/07, James Y Knight [EMAIL PROTECTED] wrote: It seems to me that a stack trace should always be attached to an exception object at creation time of the exception, and never at any other time. Sounds good in principle - but don't forget that normally the

Re: [Python-Dev] with_traceback

2007-02-28 Thread glyph
On Wed, 28 Feb 2007 18:10:21 -0800, Guido van Rossum [EMAIL PROTECTED] wrote: I am beginning to think that there are serious problems with attaching the traceback to the exception; I really don't like the answer that pre-creating an exception is unpythonic in Py3k. In Twisted, to deal with

Re: [Python-Dev] with_traceback

2007-02-27 Thread glyph
On Tue, 27 Feb 2007 13:37:21 +1300, Greg Ewing [EMAIL PROTECTED] wrote: I don't like that answer. I can think of legitimate reasons for wanting to pre-create exceptions, e.g. if I'm intending to raise and catch a particular exception frequently and I don't want the overhead of creating a new

[Python-Dev] with_traceback

2007-02-26 Thread Andrew Dalke
Guido's talk at PyCon said: Use raise E(arg).with_traceback(tb) instead of raise E, arg, tb That seems strange to me because of the mutability. Looking through the back discussions on this list I see Guido commented:

Re: [Python-Dev] with_traceback

2007-02-26 Thread Thomas Wouters
On 2/26/07, Andrew Dalke [EMAIL PROTECTED] wrote: My concern when I saw Guido's keynote was the worry that people do/might write code like this NO_END_OF_RECORD = ParserError(Cannot find end of record) def parse_record(input_file): ... raise NO_END_OF_RECORD ... FWIW, you can

Re: [Python-Dev] with_traceback

2007-02-26 Thread Phillip J. Eby
At 03:38 PM 2/26/2007 -0700, Andrew Dalke wrote: Guido's talk at PyCon said: Use raise E(arg).with_traceback(tb) instead of raise E, arg, tb That seems strange to me because of the mutability. Looking through the back discussions on this list I see Guido commented:

Re: [Python-Dev] with_traceback

2007-02-26 Thread Greg Ewing
Phillip J. Eby wrote: At 03:38 PM 2/26/2007 -0700, Andrew Dalke wrote: NO_END_OF_RECORD = ParserError(Cannot find end of record) Then don't do that, as it's bad style for Python 3.x. ;-) I don't like that answer. I can think of legitimate reasons for wanting to pre-create exceptions, e.g.

Re: [Python-Dev] with_traceback

2007-02-26 Thread Andrew Dalke
PJE: Then don't do that, as it's bad style for Python 3.x. ;-) It's bad style for 3.x only if Python goes with this interface. If it stays with the 2.x style then there's no problem. There may also be solutions which are cleaner and which don't mutate the exception instance. I am not