[issue24205] signature.bind error messages are sub-optimal

2015-05-18 Thread Yury Selivanov

Yury Selivanov added the comment:

Hi David,
Please see the attached patch. It doesn't make Signature.bind() exceptions look 
exactly like system messages, but it's now much closer.

--
keywords: +patch
Added file: http://bugs.python.org/file39422/sig_exc.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24205
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24205] signature.bind error messages are sub-optimal

2015-05-18 Thread Yury Selivanov

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


--
assignee:  - yselivanov

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24205
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24205] signature.bind error messages are sub-optimal

2015-05-18 Thread Martin Panter

Martin Panter added the comment:

I think the patch is okay. Just beware that next(iter(kwargs)) can return 
different names if there is more than one unexpected argument, so the error 
message could vary. But it looks like the test cases are only when there is 
exactly one extra argument, so no problem.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24205
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24205] signature.bind error messages are sub-optimal

2015-05-18 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 3cc368d334c5 by Yury Selivanov in branch 'default':
Issue 24205: Improve inspect.Signature.bind() error messages.
https://hg.python.org/cpython/rev/3cc368d334c5

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24205
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24205] signature.bind error messages are sub-optimal

2015-05-18 Thread Yury Selivanov

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


--
resolution:  - fixed
stage:  - resolved
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24205
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24205] signature.bind error messages are sub-optimal

2015-05-15 Thread Martin Panter

Changes by Martin Panter vadmium...@gmail.com:


--
nosy: +vadmium

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24205
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24205] signature.bind error messages are sub-optimal

2015-05-15 Thread Ethan Furman

Changes by Ethan Furman et...@stoneleaf.us:


--
nosy: +ethan.furman

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24205
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24205] signature.bind error messages are sub-optimal

2015-05-15 Thread R. David Murray

New submission from R. David Murray:

I have an application where I'm calling a handler function with passed in 
arguments.  I want to generate an error if the handler is called with the wrong 
arguments.  I can't just catch TypeError since a TypeError could easily result 
from some programming error in the handler, rather than an error in the calling 
args.  So, doing this seems obvious:

sig = signature(handler)
try:
bound = sig.bind(message, payload, *args, **kw)
except TypeError as exc:
print(Invalid handler call: {}.format(str(exc))
handler(*bound.args, **bound.kwargs)

Now, suppose I have a function like:

def foo(message, payload, anarg, akeyword='bar'):
pass

If I call it directly with an invalid keyword argument I get:

 foo(1, 2, 3, badword=7)
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: foo() got an unexpected keyword argument 'badword'

However, bind gives me:

 sig.bind(1, 2, 3, badword=7)
Traceback (most recent call last):
  File stdin, line 1, in module
  File /home/rdmurray/python/p35/Lib/inspect.py, line 2818, in bind
return args[0]._bind(args[1:], kwargs)
  File /home/rdmurray/python/p35/Lib/inspect.py, line 2809, in _bind
raise TypeError('too many keyword arguments')
TypeError: too many keyword arguments

Similarly, for a missing argument I get:

 foo(1, 2)
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: foo() missing 1 required positional argument: 'anarg'

While bind gives:

 sig.bind(1, 2)
Traceback (most recent call last):
  File stdin, line 1, in module
  File /home/rdmurray/python/p35/Lib/inspect.py, line 2818, in bind
return args[0]._bind(args[1:], kwargs)
  File /home/rdmurray/python/p35/Lib/inspect.py, line 2737, in _bind
raise TypeError(msg) from None
TypeError: 'anarg' parameter lacking default value

So, using this to replace catching the TypeError from incorrectly calling a 
function does not work.  Nor are the messages in fact accurate.  Is there any 
chance we could make bind's error handling work like regular function binding?  
That's certainly what I expected would happen!

--
components: Library (Lib)
messages: 243287
nosy: r.david.murray, yselivanov
priority: normal
severity: normal
status: open
title: signature.bind error messages are sub-optimal
type: behavior
versions: Python 3.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24205
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com