Uh oh!
There was an error while loading. Please reload this page.
gh-108901: Add bound_arg to Signature.from_callable() and signature() - #116559
gh-108901: Add bound_arg to Signature.from_callable() and signature()#116559sobolevn wants to merge 10 commits into
bound_arg to Signature.from_callable() and signature()#116559Conversation
…and `signature()`
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Victor Stinner <vstinner@python.org>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
vstinner
commented
Mar 11, 2024
By the way, @pitrou: Do you have an opinion on the parameter name? :-) |
I would prefer to have Lines 1404 to 1413 in 4e5df20 |
vstinner
commented
Mar 11, 2024
skip_bound_arg=False is a double negation, and I'm always confused by double negation :-( bound_arg=True is more straightfoward to me. Previously, the argument was private, no? |
sobolevn
commented
Mar 11, 2024
Yes, it was private. It only existed on protected |
Uh oh!
There was an error while loading. Please reload this page.
skip_bound_arg to Signature.from_callable() and signature()bound_arg to Signature.from_callable() and signature()sobolevn
commented
Apr 24, 2024
Done, now it is named |
encukou
commented
Apr 25, 2024
What's the motivation for this change? I can't find the discussion behind it. My worry is that it only works on some callables, and it's not very clear which ones those are -- or how to make a custom callable (e.g. one implemented in the C API) work like a method. |
sobolevn
commented
Apr 25, 2024
I want to deprecate Lines 1403 to 1423 in 2c45148
It will work exactly like this older function. |
encukou
commented
Apr 25, 2024
Is this behaviour useful, or is it a bug that's kept in |
| If *bound_arg* is ``False``, remove ``self`` parameter | ||
| from the method signature. |
There was a problem hiding this comment.
It's better to describe the non-default behaviour for boolean options (so folks know what they'll get if they request non-default behaviour):
| If *bound_arg* is ``False``, remove ``self`` parameter | |
| from the method signature. | |
| If *bound_arg* is ``True``, report the (already bound) first parameter on bound | |
| instance or class methods (usually ``self`` or ``cls``). This emulates the historical | |
| behaviour of the deprecated :func:`getfullargspec` function. |
(Describing both behaviours is also an option, but it seemed excessively verbose in this case)
| * Add *bound_arg* parameter to :func:`inspect.Signature.from_callable` | ||
| and :func:`inspect.signature`: keep the ``self`` parameter | ||
| in the method signature if *bound_arg* is True. |
There was a problem hiding this comment.
Reword here to match the updated main function docs (including mentioning the getfullargspec compatibility)
| * Add *bound_arg* parameter to :func:`inspect.Signature.from_callable` | ||
| and :func:`inspect.signature`: keep the ``self`` parameter | ||
| in the method signature if *bound_arg* is True. | ||
| :pypi:`inspect313` package has a backport of this feature. |
There was a problem hiding this comment.
Maybe make the backport mention a seealso note in the module docs rather than only putting it here?
| @@ -0,0 +1,3 @@ | |||
| Add *bound_arg* keyword-only parameter to | |||
| :func:`inspect.Signature.from_callable` and :func:`inspect.signature`. | |||
| If *bound_arg* is ``True``, keep ``self`` parameter in method a signature. | |||
There was a problem hiding this comment.
Mention the getfullargspec compatibility aspect here.
vstinner
commented
Apr 29, 2024
IMO it's useful in general, not only for backward compatibility. Keep self or not should be configurable. |
I think it was primarily a quirk of the way However, the suggested flag isn't hard to maintain, since the complexity is in the branch that corrects the underlying function signature to remove the already bound first parameter (the default behaviour). The "unwrap bound methods" branch is literally just Line 2517 in 3989894 I do think making the flag public is worth including as a step prior to full programmatic deprecation of (The one potential argument I see for a parameter name like |
encukou
commented
Apr 30, 2024
My worry is that while the flag isn't hard to maintain as an internal detail of how (Unfortunately I'll probably not have time to investigate this worry before beta 1. If the feature is waiting for my review, it won't make it.) |
This PR is stale because it has been open for 30 days with no activity. |
inspectmodule, deprecate old incorrect APIs #108901📚 Documentation preview 📚: https://cpython-previews--116559.org.readthedocs.build/