#1 Use standard syntax for ‘raise’ with exception instances.

open-rejected
nobody
None
5
2010-06-15
2010-06-15
Anonymous
No

The standard Python format for ‘raise’ is with a single argument: the exception instance to raise. Further, the exception instance should be a subclass somewhere in the exception hierarchy.

Other forms of the statement are long deprecated, and in Python 2.6 string exceptions are obsolete.

This patch converts all ‘raise’ statements to use the standard syntax, and to use exception instances instead of strings.

It originates from addressing Debian Bug#585187 http://bugs.debian.org/585187

Discussion

  • Armin Rigo
    Armin Rigo
    2010-06-15

    • status: open --> open-rejected
     
  • Armin Rigo
    Armin Rigo
    2010-06-15

    Your patch is mostly about a form of the Python "raise" statement that is not deprecated at all. Indeed, even with -Wall, typing "raise KeyError, 123" in a Python 2.6 prompt does not give me any warning at all. The patch only fixes a single example of a string exception; I committed this one, thanks for bringing this up. The rest is merely a question of style and won't be "fixed" as I see nothing wrong.

     

  • Anonymous
    2010-06-15

    I should have clarified; the deprecation is progressive.

    In Python 2.6 and later, raising objects that are not exception instances is forbidden.

    In Python 3 and later, any syntax except ‘raise exception_instance’ is forbidden.

    So I was addressing both of those with this patch.