Skip to content

Python 3 preparation: Change syntax of raise statement #15990

@wluebbe

Description

@wluebbe
mannequin

Only the modern syntax like raise E(V) and raise E(V).with_traceback(T) is accepted by Python 3.

Almost all cases change raise E, V to raise E(V) where V is a string.

TODO:

  • Clarify why the cases with_traceback were omitted in libfuturize/fixes/raise.py. (Perhaps this belongs to stage 2?)

Changes according to lib2to3/fixes/fix_raise.py:

raise         -> raise
raise E       -> raise E
raise E, V    -> raise E(V)
raise E, V, T -> raise E(V).with_traceback(T)
raise E, None, T -> raise E.with_traceback(T)

raise (((E, E'), E''), E'''), V -> raise E(V)
raise "foo", V, T               -> warns about string exceptions

CAVEATS:
   "raise E, V" will be incorrectly translated if V is an exception
   instance. The correct Python 3 idiom is
       raise E from V
   but since we can't detect instance-hood by syntax alone and since
   any client code would have to be changed as well, we don't automate
   this.

CC: @tscrim

Component: distribution

Author: Wilfried Luebbe

Branch/Commit: 136948a

Reviewer: R. Andrew Ohana

Issue created by migration from https://trac.sagemath.org/ticket/15990

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions