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 <rep...@bugs.python.org> <http://bugs.python.org/issue24474> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com