You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*args should have been left in even for the bound method, as idlelib calltips do.
Since '*' is not a word character,
idlelib.Calltips._first_param = re.compile('(?<=\()\w*\,?\s*')
does not see '*args' as a substring to be deleted with
argspec = _first_param.sub("", argspec)
The same comment applies to
def meth2(**kwds): pass
even though calling the bound method would fail.
There does not appear to be a test for this. If so, this case may not have ever worked right. Here is the only failure at the moment (which should also be fixed).
F:\Python\dev>4\py34\pcbuild\python_d.exe -m test test_inspect
[1/1] test_inspect
test test_inspect failed -- Traceback (most recent call last):
File "F:\Python\dev\4\py34\lib\test\test_inspect.py", line 1623, in test_signature_on_builtins
test_callable(type)
File "F:\Python\dev\4\py34\lib\test\test_inspect.py", line 1604, in test_callable
signature = inspect.signature(o)
File "F:\Python\dev\4\py34\lib\inspect.py", line 1555, in signatureraiseValueError('callable {!r} is not supported by signature'.format(obj))
ValueError: callable <class 'type'> is not supported by signature
Is there any reason that the second case Terry provide still will failed with ValueError?
classC:
defmeth2(**kwds): pass
ip.signature(C().meth2)
Traceback (most recent call last):
File "/home/linux/Python/cpython/Lib/idlelib/idle_test/test_calltips.py", line 139, in test_starred_parameterself.assertEqual(signature(meth), mtip)
File "/home/linux/Python/cpython/Lib/idlelib/calltips.py", line 149, in get_argspec
argspec =str(inspect.signature(fob))
File "/home/linux/Python/cpython/Lib/inspect.py", line 3028, in signaturereturn Signature.from_callable(obj, follow_wrapped=follow_wrapped)
File "/home/linux/Python/cpython/Lib/inspect.py", line 2778, in from_callable
follow_wrapper_chains=follow_wrapped)
File "/home/linux/Python/cpython/Lib/inspect.py", line 2195, in _signature_from_callablereturn _signature_bound_method(sig)
File "/home/linux/Python/cpython/Lib/inspect.py", line 1785, in _signature_bound_methodraiseValueError('invalid method signature')
ValueError: invalid method signature
Activity
terryjreedy commentedon Jan 27, 2014
*args should have been left in even for the bound method, as idlelib calltips do.
Since '*' is not a word character,
idlelib.Calltips._first_param = re.compile('(?<=\()\w*\,?\s*')
does not see '*args' as a substring to be deleted with
argspec = _first_param.sub("", argspec)
The same comment applies to
def meth2(**kwds): pass
even though calling the bound method would fail.
larryhastings commentedon Jan 27, 2014
Yury, can you look in to this?
I have been modifying inspect.signature, but (almost) exclusively in from_builtin. If this is my fault I'll be happy to fix it.
terryjreedy commentedon Jan 27, 2014
There does not appear to be a test for this. If so, this case may not have ever worked right. Here is the only failure at the moment (which should also be fixed).
larryhastings commentedon Jan 27, 2014
I just tried it in 3.3 (3.3.1rc1) and it had the same problem.
1st1 commentedon Jan 27, 2014
Yes, that's s bug. I'll take a look tomorrow.
terryjreedy commentedon Jan 27, 2014
Sorry, I should have said that I tried repository versions of both 3.3 and 3.4.
1st1 commentedon Jan 28, 2014
Patch is attached, please review.
Should we commit this to 3.3 too?
python-dev commentedon Jan 28, 2014
New changeset 3544827d42e6 by Yury Selivanov in branch 'default':
inspect.signature: Handle bound methods with '(*args)' signature correctly bpo-20401
http://hg.python.org/cpython/rev/3544827d42e6
1st1 commentedon Jan 28, 2014
Committed. Thank you, Terry.
mlouielu commentedon Apr 30, 2017
Is there any reason that the second case Terry provide still will failed with ValueError?
ip.signature(C().meth2)
1st1 commentedon May 1, 2017
Yes, the reason is that
C().meth2is an invalid method that can't be called. Try callingC().meth2()and you will get a TypeError.There is no bug here.
terryjreedy commentedon May 2, 2017
OK, we will change this example in test_calltips once calltips uses .signature (bpo-19903).