homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients benjamin.peterson, ethan.furman, ncoghlan, rhettinger, serhiy.storchaka
Date 2020年02月23日.22:13:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1582495998.94.0.140176225455.issue39725@roundup.psfhosted.org>
In-reply-to
Content
It is more complicated. In the following example
try:
 try:
 raise TypeError
 except:
 try:
 try:
 raise OverflowError
 except:
 raise ValueError
 except:
 raise KeyError from None
except BaseException as exc:
 e = exc
the __context__ chain is KeyError -> ValueError -> OverflowError -> TypeError. We want to suppress ValueError and OverflowError, and keep KeyError -> TypeError. I afraid that the chain of exceptions just do not have enough information to do this. Maybe analyzing tracebacks can help, but it looks too complex.
Maybe the simpler solution is to "cut" __context__ when we leave an exception handler. If __suppress_context__ is true and the current handled exception is not __context__, set it as __context__.
Here is a PR which implements this solution. I am not sure that it is correct, and it may miss some corner cases, it is just an example. Pay attention to the ipaddress module: in some cases we want to suppress more than one exception, and currently it is inconvenient.
Maybe we incorrectly handle exception chains. Maybe they should be build in a way similar to tracebacks: initially set __context__ to None and add a handled exception to the end of the chain when leave an exception handler.
History
Date User Action Args
2020年02月23日 22:13:18serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, ncoghlan, benjamin.peterson, ethan.furman
2020年02月23日 22:13:18serhiy.storchakasetmessageid: <1582495998.94.0.140176225455.issue39725@roundup.psfhosted.org>
2020年02月23日 22:13:18serhiy.storchakalinkissue39725 messages
2020年02月23日 22:13:18serhiy.storchakacreate

AltStyle によって変換されたページ (->オリジナル) /