classification
Title: Correct the description of sys.exc_info() and add a code example
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.9, Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: cheryl.sabella, docs@python, maggyero, mdk
Priority: normal Keywords: patch, patch, patch

Created on 2019-01-20 16:39 by maggyero, last changed 2020-12-21 13:14 by mdk. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 11625 merged maggyero, 2019-01-20 16:56
PR 11625 merged maggyero, 2019-01-20 16:56
PR 11625 merged maggyero, 2019-01-20 16:56
Messages (2)
msg334092 - (view) Author: Géry (maggyero) * Date: 2019-01-20 16:39
In the documentation of the try statement (https://docs.python.org/3/reference/compound_stmts.html#the-try-statement), I think that the sentence:

"sys.exc_info() values are restored to their previous values (before the call) when returning from a function that handled an exception."

should be replaced by this sentence:

"sys.exc_info() values are restored to their previous values (before the call) when leaving an exception handler."

as proven by this code which does not use any "function that handled an exception" and yet restores sys.exc_info() values:


>>> try:
...     raise ValueError
... except:
...     try:
...          raise TypeError
...     except:
...         print(sys.exc_info())
...     print(sys.exc_info())
... 
(<class 'TypeError'>, TypeError(), <traceback object at 0x10ca19bc8>)
(<class 'ValueError'>, ValueError(), <traceback object at 0x10ca19c08>)
msg383516 - (view) Author: Julien Palard (mdk) * (Python committer) Date: 2020-12-21 13:13
New changeset d515c610c61b9a8c40c037a3dc3bfc8d67563658 by Géry Ogam in branch 'master':
bpo-35790: Correct the description of sys.exc_info() and add a code example (GH-11625)
https://github.com/python/cpython/commit/d515c610c61b9a8c40c037a3dc3bfc8d67563658
History
Date User Action Args
2020-12-21 13:14:44mdksetkeywords: patch, patch, patch
status: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-12-21 13:13:39mdksetmessages: + msg383516
2020-10-09 14:16:06maggyerosetnosy: + cheryl.sabella, - ezio.melotti, eric.araujo, willingc
versions: + Python 3.6, Python 3.8, Python 3.9

type: enhancement
title: Correct a statement about sys.exc_info() values restoration -> Correct the description of sys.exc_info() and add a code example
2019-01-20 16:57:10maggyerosetkeywords: + patch
stage: patch review
pull_requests: + pull_request11388
2019-01-20 16:57:02maggyerosetkeywords: + patch
stage: (no value)
pull_requests: + pull_request11387
2019-01-20 16:56:50maggyerosetkeywords: + patch
stage: (no value)
pull_requests: + pull_request11386
2019-01-20 16:39:44maggyerocreate