mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
bpo-29762: More use "raise from None". (#569)
This hides unwanted implementation details from tracebacks.
This commit is contained in:
parent
43ba8861e0
commit
5affd23e6f
30 changed files with 50 additions and 48 deletions
|
|
@ -209,7 +209,7 @@ def _setoption(arg):
|
|||
if lineno < 0:
|
||||
raise ValueError
|
||||
except (ValueError, OverflowError):
|
||||
raise _OptionError("invalid lineno %r" % (lineno,))
|
||||
raise _OptionError("invalid lineno %r" % (lineno,)) from None
|
||||
else:
|
||||
lineno = 0
|
||||
filterwarnings(action, message, category, module, lineno)
|
||||
|
|
@ -233,7 +233,7 @@ def _getcategory(category):
|
|||
try:
|
||||
cat = eval(category)
|
||||
except NameError:
|
||||
raise _OptionError("unknown warning category: %r" % (category,))
|
||||
raise _OptionError("unknown warning category: %r" % (category,)) from None
|
||||
else:
|
||||
i = category.rfind(".")
|
||||
module = category[:i]
|
||||
|
|
@ -241,11 +241,11 @@ def _getcategory(category):
|
|||
try:
|
||||
m = __import__(module, None, None, [klass])
|
||||
except ImportError:
|
||||
raise _OptionError("invalid module name: %r" % (module,))
|
||||
raise _OptionError("invalid module name: %r" % (module,)) from None
|
||||
try:
|
||||
cat = getattr(m, klass)
|
||||
except AttributeError:
|
||||
raise _OptionError("unknown warning category: %r" % (category,))
|
||||
raise _OptionError("unknown warning category: %r" % (category,)) from None
|
||||
if not issubclass(cat, Warning):
|
||||
raise _OptionError("invalid warning category: %r" % (category,))
|
||||
return cat
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue