Changes between Version 58 and Version 59 of DeveloperGuidelines/Py_2_3


Ignore:
Timestamp:
07/05/19 23:14:07 (6 years ago)
Author:
Dominic König
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelines/Py_2_3

    v58 v59  
    4949    ...
    5050}}}
     51
     52=== Raise Exceptions Instances ===
     53
     54Python-3 does no longer support the {{{raise E, V, T}}} syntax - the new syntax is {{{raise E(V).with_traceback(T)}}}.
     55
     56However, the traceback is rarely required - and where E is an Exception class (rather than a string), we can use the {{{raise E(V)}}} syntax which works in all Python versions.
     57
     58{{{#!python
     59# Works in Py2, but not in Py3:
     60raise SyntaxError, "Error Message"
     61
     62# Works in all Python versions, hence our Standard:
     63raise SyntaxError("Error Message")
     64}}}
     65
     66If a traceback object must be passed (which is rarely needed), then we must use the PY2 constant to implement alternative statements.
    5167
    5268=== No exec statements ===
     
    8096}}}
    8197
    82 === Raise Exceptions Instances ===
    83 
    84 Python-3 does no longer support the {{{raise E, V, T}}} syntax - the new syntax is {{{raise E(V).with_traceback(T)}}}.
    85 
    86 However, the traceback is rarely required - and where E is an Exception class (rather than a string), we can use the {{{raise E(V)}}} syntax which works in all Python versions.
    87 
    88 {{{#!python
    89 # Works in Py2, but not in Py3:
    90 raise SyntaxError, "Error Message"
    91 
    92 # Works in all Python versions, hence our Standard:
    93 raise SyntaxError("Error Message")
    94 }}}
    95 
    96 If a traceback object must be passed (which is rarely needed), then we must use the PY2 constant to implement alternative statements.
    9798== Usage ==
    9899