String Exceptions (PEP 352)

T

Thomas Guettler

Hi,

I like python because it is compatible to old versions. That's way I think
string exceptions should not be deprecated.

I use string exceptions if the condition for an assertion is
to complex:

if foo and bar and i>10:
raise "if foo and bar i must not be greater than 10"

This way I can easily add "checkpoints" to my code.

Is it too late to change this? Way not make this line

raise "..."

behave like this:

raise Exception("...")

in the future?

I know that catching string exceptions and reading the
string is different from Exception("..."). This could
become deprecated.

Please keep Python compatible to old versions.

Thomas Güttler
 
I

infidel

You could also use the "assert" statement:
.... assert i <= 10, "if foo and bar then i must not be greater than
10"
....
 
B

bruno at modulix

Thomas said:
Hi,

I like python because it is compatible to old versions. That's way I think
string exceptions should not be deprecated.

I use string exceptions if the condition for an assertion is
to complex:

if foo and bar and i>10:
raise "if foo and bar i must not be greater than 10"

What's wrong with:

assert foo and bar and i > 10, \
"if foo and bar i must not be greater than 10"



(snip)
Please keep Python compatible to old versions.

<MHO>
When there's too much hysterical cruft and warts accumulated from the
past, it's time to throw away and clean up, even if it breaks a lot of
things. Trying to keep compatibility at any price would be just suicidal
IMHO - time to get rid of old warts and come back to simplicity. "one
obvious way to do it" rules.
</MHO>
 
B

bruno at modulix

bruno said:
What's wrong with:

assert foo and bar and i > 10, \
"if foo and bar i must not be greater than 10"

oops ! I meant:
if foo and bar:
assert i > 10, "if foo and bar i must not be greater than 10"

My bad :(
 
T

Terry Reedy

Thomas Guettler said:
I like python because it is compatible to old versions.

Python 3 will be a new and mostly improved dialect of Python.
Some 2.x code will run unchanged. Much will not. Transition tools will be
written.
That's way I think string exceptions should not be deprecated.
Is it too late to change this?
Yes.

Way not make this line raise "..."
behave like this: raise Exception("...")

Part of the motivation for 3.0 is to remove duplication and *simply* the
language (= easier to learn), parser, compiler, and interpreter.

Terry Jan Reedy
 
B

Ben Finney

Thomas Guettler said:
I like python because it is compatible to old versions.

I like it because it has a documented, manageable procedure for
breaking compatibility with old versions.
if foo and bar and i>10:
raise "if foo and bar i must not be greater than 10"

Others have pointed out that this is a job for 'assert'.
Is it too late to change this?

Yes. PEP-0352 has a status of "Final".
Way not make this line

raise "..."

behave like this:

raise Exception("...")

in the future?

Because explicit is better than implicit, and special magic behaviour
is to be deprecated (or never implemented) when possible.
Please keep Python compatible to old versions.

Have a read of PEP 0005:

<URL:http://www.python.org/dev/peps/pep-0005>

Also note that the transition plan (documented in the PEP that
concerns you) shows the support for the old behaviour is not to be
dropped until Python 3.0, a release explicitly targeted at breaking
backward compatibility to clean out crufty behaviour.
 
P

Paul Rubin

bruno at modulix said:
What's wrong with:

assert foo and bar and i > 10, \
"if foo and bar i must not be greater than 10"

It doesn't necessarily do anything. With optimization enable, assert
is a no-op.
 
B

bruno at modulix

Paul said:
It doesn't necessarily do anything. With optimization enable, assert
is a no-op.

quoting the OP (emphasis is mine):
"""
I use string exceptions if the condition for an *assertion* is
to complex:
"""
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top