[issue24474] Accidental exception chaining in inspect.Signature.bind()
Walter Dörwald
report at bugs.python.org
Fri Jun 19 18:16:29 CEST 2015
New submission from Walter Dörwald:
When an exception is raised by inspect.Signature.bind() in some cases the exception has a StopIteration as its __context__:
import inspect
try:
inspect.signature(lambda x:None).bind()
except Exception as exc:
print(repr(exc))
print(repr(exc.__context__))
This prints:
TypeError("missing a required argument: 'x'",)
StopIteration()
I would have expected it to print:
TypeError("missing a required argument: 'x'",)
None
This reason for this is that the code in bind() has nested exception handlers. The innermost handler does
raise TypeError(...) from None
to drop the exception context, but another context exception gets added by the outermost exception handler.
----------
messages: 245506
nosy: doerwalter
priority: normal
severity: normal
status: open
title: Accidental exception chaining in inspect.Signature.bind()
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24474>
_______________________________________
More information about the Python-bugs-list
mailing list