Issue 20401: inspect.signature removes initial starred method params (bug)
Created on 2014-01-27 02:16 by terry.reedy, last changed 2022-04-11 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| signature_method_first_arg_01.patch | yselivanov, 2014-01-28 00:03 | review | ||
| Messages (12) | |||
|---|---|---|---|
| msg209378 - (view) | Author: Terry J. Reedy (terry.reedy) * ![]() |
Date: 2014-01-27 02:16 | |
>>> import inspect
>>> class C:
def meth(*args): pass
>>> str(inspect.signature(C.meth))
'(*args)'
>>> c=C()
>>> str(s=inspect.signature(c.meth))
'()'
*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.
|
|||
| msg209379 - (view) | Author: Larry Hastings (larry) * ![]() |
Date: 2014-01-27 02:28 | |
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. |
|||
| msg209386 - (view) | Author: Terry J. Reedy (terry.reedy) * ![]() |
Date: 2014-01-27 03:47 | |
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 signature raise ValueError('callable {!r} is not supported by signature'.format(obj)) ValueError: callable <class 'type'> is not supported by signature |
|||
| msg209387 - (view) | Author: Larry Hastings (larry) * ![]() |
Date: 2014-01-27 03:49 | |
I just tried it in 3.3 (3.3.1rc1) and it had the same problem. |
|||
| msg209393 - (view) | Author: Yury Selivanov (yselivanov) * ![]() |
Date: 2014-01-27 04:37 | |
Yes, that's s bug. I'll take a look tomorrow. |
|||
| msg209400 - (view) | Author: Terry J. Reedy (terry.reedy) * ![]() |
Date: 2014-01-27 05:35 | |
Sorry, I should have said that I tried repository versions of both 3.3 and 3.4. |
|||
| msg209488 - (view) | Author: Yury Selivanov (yselivanov) * ![]() |
Date: 2014-01-28 00:03 | |
Patch is attached, please review. Should we commit this to 3.3 too? |
|||
| msg209566 - (view) | Author: Roundup Robot (python-dev) ![]() |
Date: 2014-01-28 17:26 | |
New changeset 3544827d42e6 by Yury Selivanov in branch 'default': inspect.signature: Handle bound methods with '(*args)' signature correctly #20401 http://hg.python.org/cpython/rev/3544827d42e6 |
|||
| msg209567 - (view) | Author: Yury Selivanov (yselivanov) * ![]() |
Date: 2014-01-28 17:27 | |
Committed. Thank you, Terry. |
|||
| msg292637 - (view) | Author: Louie Lu (louielu) * | Date: 2017-04-30 17:11 | |
Is there any reason that the second case Terry provide still will failed with ValueError?
class C:
def meth2(**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_parameter
self.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 signature
return 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_callable
return _signature_bound_method(sig)
File "/home/linux/Python/cpython/Lib/inspect.py", line 1785, in _signature_bound_method
raise ValueError('invalid method signature')
ValueError: invalid method signature
|
|||
| msg292701 - (view) | Author: Yury Selivanov (yselivanov) * ![]() |
Date: 2017-05-01 21:36 | |
> Is there any reason that the second case Terry provide still will failed with ValueError? > class C: > def meth2(**kwds): pass > ip.signature(C().meth2) Yes, the reason is that `C().meth2` is an invalid method that can't be called. Try calling `C().meth2()` and you will get a TypeError. There is no bug here. |
|||
| msg292711 - (view) | Author: Terry J. Reedy (terry.reedy) * ![]() |
Date: 2017-05-02 02:22 | |
OK, we will change this example in test_calltips once calltips uses .signature (#19903). |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:57:57 | admin | set | github: 64600 |
| 2017-05-02 02:22:59 | terry.reedy | set | messages: + msg292711 |
| 2017-05-01 21:36:19 | yselivanov | set | messages: + msg292701 |
| 2017-04-30 17:11:33 | louielu | set | nosy:
+ louielu messages: + msg292637 |
| 2014-01-28 17:27:33 | yselivanov | set | status: open -> closed resolution: fixed messages: + msg209567 |
| 2014-01-28 17:26:41 | python-dev | set | nosy:
+ python-dev messages: + msg209566 |
| 2014-01-28 00:03:49 | yselivanov | set | files:
+ signature_method_first_arg_01.patch nosy:
+ ncoghlan assignee: yselivanov |
| 2014-01-27 05:35:14 | terry.reedy | set | messages: + msg209400 |
| 2014-01-27 04:37:54 | yselivanov | set | messages: + msg209393 |
| 2014-01-27 03:49:41 | larry | set | messages: + msg209387 |
| 2014-01-27 03:47:41 | terry.reedy | set | messages: + msg209386 |
| 2014-01-27 02:40:14 | terry.reedy | link | issue19903 dependencies |
| 2014-01-27 02:28:30 | larry | set | nosy:
+ larry messages: + msg209379 |
| 2014-01-27 02:16:33 | terry.reedy | create | |

