Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document sys.exc_info behaviour difference #594

Open
sivachandran opened this issue Sep 15, 2021 · 0 comments
Open

Document sys.exc_info behaviour difference #594

sivachandran opened this issue Sep 15, 2021 · 0 comments

Comments

@sivachandran
Copy link

The following snippet produces different output between python 2 & 3

# exc_info_test.py
import sys

def f():
    try:
        raise RuntimeError()
    except Exception as e:
        print("f:", sys.exc_info())
    g()

def g():
    print("g:", sys.exc_info())

f()

Output

> python2 exc_info_test.py
('f:', (<type 'exceptions.RuntimeError'>, RuntimeError(), <traceback object at 0x7f99aa4ccd70>))
('g:', (<type 'exceptions.RuntimeError'>, RuntimeError(), <traceback object at 0x7f99aa4ccd70>))

> python3 exc_info_test.py
f: (<class 'RuntimeError'>, RuntimeError(), <traceback object at 0x7fc14fb67d00>)
g: (None, None, None)

Though the behaviour difference is documented, it is too subtle to notice the difference

https://docs.python.org/2/library/sys.html

Here, “handling an exception” is defined as “executing or having executed an except clause.” For any stack frame, only information about the most recently handled exception is accessible.

https://docs.python.org/3/library/sys.html

Here, “handling an exception” is defined as “executing an except clause.” For any stack frame, only information about the exception being currently handled is accessible.

To make the difference highlighted, I suggest to document the sys.exc_info behaviour difference in Cheat Sheets or in an appropriate page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant