Message245506
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. |
|
Date |
User |
Action |
Args |
2015-06-19 16:16:29 | doerwalter | set | recipients:
+ doerwalter |
2015-06-19 16:16:29 | doerwalter | set | messageid: <1434730589.67.0.681224722356.issue24474@psf.upfronthosting.co.za> |
2015-06-19 16:16:29 | doerwalter | link | issue24474 messages |
2015-06-19 16:16:29 | doerwalter | create | |
|