-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-96127: Fix inspect.signature
call on mocks
#96335
Conversation
Re-triggering CI. |
I have a similar PR somewhere about this, but I'm on mobile so it's tricky to find |
#94962 is this related? |
They are not related as far as I can tell :) Your PR does not fix this exact problem: gh pr checkout 94962 Python 3.12.0a0 (heads/main-dirty:a36235d5c7, Sep 11 2022, 12:23:24) [Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import inspect
>>> from unittest.mock import AsyncMock
>>> inspect.signature(AsyncMock())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/sobolev/Desktop/cpython/Lib/inspect.py", line 3272, in signature
return Signature.from_callable(obj, follow_wrapped=follow_wrapped,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/sobolev/Desktop/cpython/Lib/inspect.py", line 3020, in from_callable
return _signature_from_callable(obj, sigcls=cls,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/sobolev/Desktop/cpython/Lib/inspect.py", line 2507, in _signature_from_callable
return _signature_from_function(sigcls, obj,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/sobolev/Desktop/cpython/Lib/inspect.py", line 2351, in _signature_from_function
positional = arg_names[:pos_count]
~~~~~~~~~^^^^^^^^^^^^
TypeError: 'Mock' object is not subscriptable |
@sobolevn - could you rebase and resolve the conflicts? I think this is then good to land after another quick eyeball from a reviewer... |
Sure!
I hope we can land this now! |
@sobolevn this fix saved me big time. Thank you for your amazing work! |
Sorry @sobolevn and @cjw296, I had trouble checking out the |
Sorry, @sobolevn and @cjw296, I could not cleanly backport this to |
(cherry picked from commit 9e7d726)
(cherry picked from commit 9e7d726)
GH-101646 is a backport of this pull request to the 3.11 branch. |
GH-101647 is a backport of this pull request to the 3.10 branch. |
) (cherry picked from commit 9e7d726) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Before:
After:
Related #94050