[issue24474] Accidental exception chaining in inspect.Signature.bind()

2015-06-20 Thread Nick Coghlan

Nick Coghlan added the comment:

The sentinel form of next() is nice when there's a natural sentinel value, but 
needing to *create* a sentinel is generally a sign that the out-of-band 
exception is a better fit.

The function could likely do with some refactoring (e.g. breaking out some 
helper functions to make the logic easier to follow), but shifting from 
idiomatic code to non-idiomatic code isn't a good way of tackling that.

--

___
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



[issue24474] Accidental exception chaining in inspect.Signature.bind()

2015-06-20 Thread Yury Selivanov

Yury Selivanov added the comment:

 This isn't a bug, as raise exc from None only hides *display* of the 
 context, it doesn't lose the record of the context entirely.

Agree.  My patch, though, is still valid.  I think removing try..except blocks 
actually simplifies the code, and removes the need of using 'raise .. from 
None' completely.

--

___
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



[issue24474] Accidental exception chaining in inspect.Signature.bind()

2015-06-20 Thread Nick Coghlan

Nick Coghlan added the comment:

This isn't a bug, as raise exc from None only hides *display* of the context, 
it doesn't lose the record of the context entirely.

This means Walter's display code is incorrect, as it isn't checking for 
__suppress_context__:

 import inspect
 try:
... inspect.signature(lambda x:None).bind()
... except Exception as e:
... exc = e
... 
 exc.__suppress_context__
True

Interestingly, neither PEP 409 *nor* PEP 415 capture the rationale for that 
design: retaining the full context data even when it's hidden by the default 
exception display routines means that you can still debug code that uses raise 
X from None inappropriately. (I thought there was an open RFE to make it easy 
to force the traceback module to ignore __suppress_context__ but if there is 
one, I can't find it)

--
resolution:  - not a bug
stage: patch review - resolved
status: open - closed

___
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



[issue24474] Accidental exception chaining in inspect.Signature.bind()

2015-06-19 Thread Walter Dörwald

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



[issue24474] Accidental exception chaining in inspect.Signature.bind()

2015-06-19 Thread Yury Selivanov

Changes by Yury Selivanov yseliva...@gmail.com:


--
assignee:  - yselivanov
components: +Library (Lib)
nosy: +yselivanov
versions: +Python 3.5, Python 3.6

___
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



[issue24474] Accidental exception chaining in inspect.Signature.bind()

2015-06-19 Thread Yury Selivanov

Yury Selivanov added the comment:

Hi Walter,
Thanks for reporting this. A patch is attached.

--
keywords: +needs review, patch
nosy: +larry, ncoghlan
stage:  - patch review
Added file: http://bugs.python.org/file39743/sig.patch

___
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