Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
9seconds committed Aug 25, 2014
1 parent 29a7b3a commit 4ae50b3
Showing 1 changed file with 9 additions and 25 deletions.
34 changes: 9 additions & 25 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,37 +87,21 @@ So if we will rewrite given example with PEP3134
import sys
import pep3134
def example():
error = -1
try:
pep3134.raise_KeyError("WOW SUCH ERROR")
pep3134.raise_(KeyError("WOW SUCH ERROR"))
except KeyError as err:
error = err
first = sys.exc_info()
assert err.__traceback__ is first[2]
assert error.__traceback__ is first[2]
second = sys.exc_info()
assert err.__traceback__ is second[2] # works in Python2 only
return first, second
See? In Python 3 assert will not work but in Python 2 it will. Anyway, there is the trick. It called
``with_traceback`` method (added in Python 3 also)

.. code-block:: python
import sys
import pep3134
assert error.__traceback__ is not second[2] # works in Python 2 only
example()
def example():
try:
pep3134.raise_KeyError("WOW SUCH ERROR")
except KeyError as err:
first = sys.exc_info()
assert err.__traceback__ is first[2]
err = err.with_traceback(err.__traceback__)
second = sys.exc_info()
assert err.__traceback__ is second[2] # works in in both pythons
return first, second
This is the only pitfall. Causes, as I mentioned, work well.

Expand Down

0 comments on commit 4ae50b3

Please sign in to comment.