This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2012年04月20日 18:08 by r.david.murray, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (4) | |||
|---|---|---|---|
| msg158864 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2012年04月20日 18:08 | |
The following code: def foo(a, *, b=None): pass unittest.mock.create_autospec(foo) fails with this traceback: Traceback (most recent call last): File "temp.py", line 6, in <module> unittest.mock.create_autospec(foo) File "/home/rdmurray/python/p33/Lib/unittest/mock.py", line 2026, in create_autospec mock = _set_signature(mock, spec) File "/home/rdmurray/python/p33/Lib/unittest/mock.py", line 162, in _set_signature result = _getsignature(original, skipfirst, instance) File "/home/rdmurray/python/p33/Lib/unittest/mock.py", line 81, in _getsignature regargs, varargs, varkwargs, defaults = inspect.getargspec(func) File "/home/rdmurray/python/p33/Lib/inspect.py", line 808, in getargspec raise ValueError("Function has keyword-only arguments or annotations" ValueError: Function has keyword-only arguments or annotations, use getfullargspec() API which can support them |
|||
| msg158924 - (view) | Author: Michael Foord (michael.foord) * (Python committer) | Date: 2012年04月21日 16:49 | |
This is non-trivial to fix. Although inspect.getfullargspec can be used, which does support keyword only arguments, inspect.formatargspec *doesn't* support them. (mock.create_autospec uses these to rebuild a compatible signature for generated mocks.) The easiest route to fixing would be to extend formatargspec to optionally take extra arguments for kwonlyargs and kwonlydefaults. |
|||
| msg158927 - (view) | Author: Michael Foord (michael.foord) * (Python committer) | Date: 2012年04月21日 17:10 | |
Hmmm... looks like formatargspec does support these features but they aren't documented. If it works out I'll update the docs for inspect.formatargspec too. |
|||
| msg158928 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2012年04月21日 17:22 | |
New changeset 6f478a4aa137 by Michael Foord in branch 'default': Closes issue 14634. unittest.mock.create_autospec now supports keyword only arguments. http://hg.python.org/cpython/rev/6f478a4aa137 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:29 | admin | set | github: 58839 |
| 2012年04月21日 17:22:47 | python-dev | set | status: open -> closed nosy: + python-dev messages: + msg158928 resolution: fixed stage: test needed -> resolved |
| 2012年04月21日 17:10:56 | michael.foord | set | messages: + msg158927 |
| 2012年04月21日 17:03:30 | michael.foord | set | keywords: - easy |
| 2012年04月21日 16:49:52 | michael.foord | set | assignee: michael.foord messages: + msg158924 |
| 2012年04月20日 18:10:38 | ezio.melotti | set | nosy:
+ ezio.melotti components: + Library (Lib) stage: test needed |
| 2012年04月20日 18:08:03 | r.david.murray | create | |