Re: [Python-ideas] Arguments to exceptions

2017-07-03 Thread Ken Kundert
I think in trying to illustrate the existing behavior I made things more confusing than they needed to be. Let me try again. Consider this code. >>> import Food >>> try: ... import meals ... except NameError as e: ... name = str(e).split("'")[1] # <-- fragile code

Re: [Python-ideas] Arguments to exceptions

2017-07-03 Thread Paul Moore
On 3 July 2017 at 09:59, 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. > > Consider this code. > > >>> import Food > >>> try: > ... import meals > ... except NameError as e: >

Re: [Python-ideas] Arguments to exceptions

2017-07-03 Thread Juancarlo AƱez
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 message. The need to > unpack information that was just packed suggests that the packing was done > too > e

Re: [Python-ideas] Bytecode JIT

2017-07-03 Thread Victor Stinner
2017-07-02 14:13 GMT+02:00 Steven D'Aprano : > That only solves the problem of mysum being modified, not whether the > arguments are ints. You still need to know whether it is safe to call > some low-level (fast) integer addition routine, or whether you have to > go through the (slow) high-level Py

Re: [Python-ideas] Arguments to exceptions

2017-07-03 Thread Paul Moore
On 3 July 2017 at 20:46, Jeff Walker wrote: > I think you are fixating too much on Ken's example. I think I understand > what he > is saying and I agree with him. It is a problem I struggle with routinely. It > occurs in > the following situations: Possibly. I hadn't reread the original e

Re: [Python-ideas] Arguments to exceptions

2017-07-03 Thread Paul Moore
On 3 July 2017 at 21:56, Jeff Walker wrote: > Paul, > Indeed, nothing gets better until people change the way they do their > exceptions. Ken's suggested enhancement to BaseException does not > directly solve the problem, but it removes the roadblocks that discourage > people from passing the

Re: [Python-ideas] Arguments to exceptions

2017-07-03 Thread Jeff Walker
Paul, I think you are fixating too much on Ken's example. I think I understand what he is saying and I agree with him. It is a problem I struggle with routinely. It occurs in the following situations: 1. You are handling an exception that you are not raising. This could be because Pyth

Re: [Python-ideas] Arguments to exceptions

2017-07-03 Thread Jeff Walker
Paul, Indeed, nothing gets better until people change the way they do their exceptions. Ken's suggested enhancement to BaseException does not directly solve the problem, but it removes the roadblocks that discourage people from passing the components to the message. Seems to me that to addres

Re: [Python-ideas] Arguments to exceptions

2017-07-03 Thread MRAB
On 2017-07-03 22:44, Paul Moore wrote: On 3 July 2017 at 21:56, Jeff Walker wrote: Paul, Indeed, nothing gets better until people change the way they do their exceptions. Ken's suggested enhancement to BaseException does not directly solve the problem, but it removes the roadblocks that di

Re: [Python-ideas] Arguments to exceptions

2017-07-03 Thread Greg Ewing
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 just guessing at people's motivations, so there's little point in speculating. I've no doubt that the current situation encourages people to be lazy -- I kn

Re: [Python-ideas] Arguments to exceptions

2017-07-03 Thread Ken Kundert
All, My primary concern is gaining access to the components that make up the messages. I am not hung up on the implementation. I just proposed the minimum that I thought would resolve the issue and introduce the least amount of risk. Concerning MRAB's idea of making the named arguments attri

Re: [Python-ideas] Arguments to exceptions

2017-07-03 Thread Nick Coghlan
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 just guessing at >> people's motivations, so there's little point in speculating. > > > I've no doubt tha