Re: [Python-ideas] Arguments to exceptions

2017-07-04 Thread Greg Ewing
Terry Reedy wrote: It occurs to me that if the exception object has no reference to any python object, then all would be identical and only one cached instance should be needed. I don't think that's true now that exceptions get tracebacks attached to them. -- Greg

Re: [Python-ideas] Arguments to exceptions

2017-07-04 Thread Terry Reedy
On 7/5/2017 12:21 AM, Terry Reedy wrote: On 7/4/2017 6:31 PM, Greg Ewing wrote: Terry Reedy wrote: Attaching a *constant* string is very fast, to the consternation of people who would like the index reported. Actually, the constant string should be attached to the class, so there is no time

Re: [Python-ideas] Arguments to exceptions

2017-07-04 Thread Terry Reedy
On 7/4/2017 8:08 PM, Ken Kundert wrote: On Tue, Jul 04, 2017 at 04:54:11PM -0400, Terry Reedy wrote: There have been many proposals for what we might call RichExceptions, with more easily access information. But as Raymond Hettinger keeps pointing out, Python does not use exceptions only for

Re: [Python-ideas] Arguments to exceptions

2017-07-04 Thread Terry Reedy
On 7/4/2017 6:31 PM, Greg Ewing wrote: Terry Reedy wrote: Attaching a *constant* string is very fast, to the consternation of people who would like the index reported. Actually, the constant string should be attached to the class, so there is no time needed. Seems to me that storing the

Re: [Python-ideas] Arguments to exceptions

2017-07-04 Thread Terry Reedy
On 7/4/2017 5:47 PM, Brendan Barnwell wrote: On 2017-07-04 13:54, Terry Reedy wrote: There have been many proposals for what we might call RichExceptions, with more easily access information. But as Raymond Hettinger keeps pointing out, Python does not use exceptions only for (hopefully rare)

Re: [Python-ideas] Arguments to exceptions

2017-07-04 Thread Steven D'Aprano
On Tue, Jul 04, 2017 at 05:08:57PM -0700, Ken Kundert wrote: > On Tue, Jul 04, 2017 at 04:54:11PM -0400, Terry Reedy wrote: > > There have been many proposals for what we might call > > RichExceptions, with more easily access information. But as Raymond > > Hettinger keeps pointing out, Python

Re: [Python-ideas] Arguments to exceptions

2017-07-04 Thread Ken Kundert
On Tue, Jul 04, 2017 at 04:54:11PM -0400, Terry Reedy wrote: > There have been many proposals for what we might call > RichExceptions, with more easily access information. But as Raymond > Hettinger keeps pointing out, Python does not use exceptions only > for (hopefully rare) errors. It also

Re: [Python-ideas] Arguments to exceptions

2017-07-04 Thread Greg Ewing
Terry Reedy wrote: Attaching a *constant* string is very fast, to the consternation of people who would like the index reported. Seems to me that storing the index as an attribute would help with this. It shouldn't be much slower than storing a constant string, and formatting the message would

Re: [Python-ideas] Arguments to exceptions

2017-07-04 Thread David Mertz
If a method, why not a property? On Jul 4, 2017 2:41 PM, "Terry Reedy" wrote: > On 7/4/2017 3:32 PM, David Mertz wrote: > >> I don't see the usefulness rich exception data as at all as limited as >> this. Here's some toy code that shows a use: >> >> >> >> >> # For some

Re: [Python-ideas] Arguments to exceptions

2017-07-04 Thread Brendan Barnwell
On 2017-07-04 13:54, Terry Reedy wrote: There have been many proposals for what we might call RichExceptions, with more easily access information. But as Raymond Hettinger keeps pointing out, Python does not use exceptions only for (hopefully rare) errors. It also uses them as signals for flow

Re: [Python-ideas] Arguments to exceptions

2017-07-04 Thread Terry Reedy
On 7/4/2017 3:32 PM, David Mertz wrote: I don't see the usefulness rich exception data as at all as limited as this. Here's some toy code that shows a use: # For some reason, imports might not be ready immediately # Maybe flaky network drive, maybe need to install modules, etc # The

Re: [Python-ideas] Arguments to exceptions

2017-07-04 Thread Terry Reedy
On 7/4/2017 10:03 AM, Steven D'Aprano wrote: On Mon, Jul 03, 2017 at 01:59:02AM -0700, Ken Kundert wrote: I think in trying to illustrate the existing behavior I made things more confusing than they needed to be. Let me try again. I understood you the first time :-) I agree that scraping

Re: [Python-ideas] Arguments to exceptions

2017-07-04 Thread David Mertz
I don't see the usefulness rich exception data as at all as limited as this. Here's some toy code that shows a use: # For some reason, imports might not be ready immediately # Maybe flaky network drive, maybe need to install modules, etc # The overall program can do things too make them

Re: [Python-ideas] Arguments to exceptions

2017-07-04 Thread Steven D'Aprano
On Sun, Jul 02, 2017 at 12:19:54PM -0700, Ken Kundert wrote: > class BaseException: > def __init__(self, *args, **kwargs): > self.args = args > self.kwargs = kwargs > > def __str__(self): > template = self.kwargs.get('template') >

Re: [Python-ideas] Arguments to exceptions

2017-07-04 Thread Steven D'Aprano
On Wed, Jul 05, 2017 at 12:10:26AM +1000, Steven D'Aprano wrote: > I think Ken is right that *if* this problem is worth solving, we should > solve it in BaseException (or at least StandardException), Oops, I forgot that StandardException is gone. And it used to be spelled StandardError. --

Re: [Python-ideas] Arguments to exceptions

2017-07-04 Thread Steven D'Aprano
On Mon, Jul 03, 2017 at 10:44:20PM +0100, Paul Moore wrote: > > 1. Change BaseException. This allows people to pass the components > > to the message without ruining str(e). > > I dispute this is the essential place to start. If nothing else, the > proposed approach encourages people to use

Re: [Python-ideas] Arguments to exceptions

2017-07-04 Thread Steven D'Aprano
On Mon, Jul 03, 2017 at 01:46:14PM -0600, Jeff Walker wrote: > Consider this example: > > import json > > > > >>> s = '{"abc": 0,

Re: [Python-ideas] Arguments to exceptions

2017-07-04 Thread Steven D'Aprano
On Mon, Jul 03, 2017 at 06:29:05AM -0400, Juancarlo AƱez wrote: > On Mon, Jul 3, 2017 at 4:59 AM, Ken Kundert > wrote: > > > That is the problem. To write the error handler, I need the misspelled > > name. > > The only way to get it is to extract it from the error

Re: [Python-ideas] Arguments to exceptions

2017-07-04 Thread Steven D'Aprano
On Mon, Jul 03, 2017 at 01:59:02AM -0700, Ken Kundert wrote: > I think in trying to illustrate the existing behavior I made things more > confusing than they needed to be. Let me try again. I understood you the first time :-) I agree that scraping the name from the NameError exception is a

Re: [Python-ideas] Arguments to exceptions

2017-07-04 Thread Paul Moore
On 4 July 2017 at 06:08, Nick Coghlan wrote: > On 4 July 2017 at 09:46, Greg Ewing wrote: >> Paul Moore wrote: >>> >>> As noted, I disagree that people are not passing components because >>> str(e) displays them the way it does. But we're both