String Exceptions (PEP 352)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas Guettler

    #1

    String Exceptions (PEP 352)


    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 "checkpoint s" 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

    --
    Thomas Güttler, http://www.thomas-guettler.de/
    E-Mail: guettli (*) thomas-guettler + de
    Spam Catcher: niemand.leerman n@thomas-guettler.de

  • infidel

    #2
    Re: String Exceptions (PEP 352)

    You could also use the "assert" statement:
    [color=blue][color=green][color=darkred]
    >>> if foo and bar:[/color][/color][/color]
    .... assert i <= 10, "if foo and bar then i must not be greater than
    10"
    ....

    Comment

    • bruno at modulix

      #3
      Re: String Exceptions (PEP 352)

      Thomas Guettler wrote:[color=blue]
      > 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"[/color]

      What's wrong with:

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



      (snip)[color=blue]
      >
      > Please keep Python compatible to old versions.[/color]

      <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>

      --
      bruno desthuilliers
      python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
      p in 'onurb@xiludom. gro'.split('@')])"

      Comment

      • bruno at modulix

        #4
        Re: String Exceptions (PEP 352)

        bruno at modulix wrote:[color=blue]
        > Thomas Guettler wrote:
        >[color=green]
        >>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"[/color]
        >
        >
        > What's wrong with:
        >
        > assert foo and bar and i > 10, \
        > "if foo and bar i must not be greater than 10"
        >[/color]

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

        My bad :(


        --
        bruno desthuilliers
        python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
        p in 'onurb@xiludom. gro'.split('@')])"

        Comment

        • Terry Reedy

          #5
          Re: String Exceptions (PEP 352)


          "Thomas Guettler" <niemand.leerma nn@thomas-guettler.de> wrote in message
          news:pan.2006.0 4.27.14.18.41.7 58387@thomas-guettler.de...[color=blue]
          >I like python because it is compatible to old versions.[/color]

          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.
          [color=blue]
          > That's way I think string exceptions should not be deprecated.
          > Is it too late to change this?[/color]

          Yes.
          [color=blue]
          > Way not make this line raise "..."
          > behave like this: raise Exception("..." )[/color]

          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



          Comment

          • Ben Finney

            #6
            Re: String Exceptions (PEP 352)

            Thomas Guettler <niemand.leerma nn@thomas-guettler.de> writes:
            [color=blue]
            > I like python because it is compatible to old versions.[/color]

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

            Others have pointed out that this is a job for 'assert'.
            [color=blue]
            > Is it too late to change this?[/color]

            Yes. PEP-0352 has a status of "Final".
            [color=blue]
            > Way not make this line
            >
            > raise "..."
            >
            > behave like this:
            >
            > raise Exception("..." )
            >
            > in the future?[/color]

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

            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.

            --
            \ "I went to the hardware store and bought some used paint. It |
            `\ was in the shape of a house." -- Steven Wright |
            _o__) |
            Ben Finney

            Comment

            • Paul Rubin

              #7
              Re: String Exceptions (PEP 352)

              bruno at modulix <onurb@xiludom. gro> writes:[color=blue]
              > What's wrong with:
              >
              > assert foo and bar and i > 10, \
              > "if foo and bar i must not be greater than 10"[/color]

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

              Comment

              • bruno at modulix

                #8
                Re: String Exceptions (PEP 352)

                Paul Rubin wrote:[color=blue]
                > bruno at modulix <onurb@xiludom. gro> writes:
                >[color=green]
                >>What's wrong with:
                >>
                >>assert foo and bar and i > 10, \
                >> "if foo and bar i must not be greater than 10"[/color]
                >
                >
                > It doesn't necessarily do anything. With optimization enable, assert
                > is a no-op.[/color]

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

                --
                bruno desthuilliers
                python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
                p in 'onurb@xiludom. gro'.split('@')])"

                Comment

                Working...