-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
inspect: Deprecate getfullargspec? #64637
Comments
Should we finally deprecate getfullargspec? With the AC and positional-only parameters support, getfullargspec doesn't provide full information anymore. By deprecation I mean changing its existing note "Consider using the new Signature Object interface, which provides a better way of introspecting functions." to "Deprecated since version 3.4: Use inspect.signature() instead". |
I vote deprecation with no stated plans of removal |
Although I say do it in 3.5. |
As Brett said - let's do a documented deprecation in 3.5. |
In this patch, I deprecate the inspect.getfullargspec function in the documentation and raise an warnings.warn with DeprecationWarning. Need feedback, because the inspect.getargspec() informs the user that it can use the getfullargspec() and I think we should use inspect.signature instead of inspect.getfullargspec() and inspect.getargspec(). Thank you |
Here is the output of my test:
/private/tmp/python/lib/python3.5/inspect.py:955: DeprecationWarning: Use inspect.signature() instead of inspect.getfullargspec() |
I was thinking about suggesting we don't code deprecate getfullargspec() but the function seems to be new to Python 3 and so that worry for Python 2/3 code is not founded. |
How about we deprecate with a warning getfullargspec(); deprecate getargspec() in docs only (in 3.6 we'll fully deprecate all function parameters API except Signature)? |
Just one thing, how do you work for the deprecation?
What's the strategy in this case or in general? Thanks |
How warnings are handled vary from case to case. Typically its documentation-only if we want to warn people that they shouldn't use something because there is a better alternative but the code is not fundamentally broken and its in Python 2. If there is something wrong with it or it's just in Python 3 then a deprecation warning with a decided amount of time for when the code will be removed. |
ok, so in this case, I can only change the documentation with a ".. deprecated:". But for the future, how can we know we have to deprecate this function for >= 3.6 ? Will you parse the documentation and check there is an deprecation to add in the code? Or is there a file with the "future" deprecations? Are you agree with the deprecation in the documentation? |
I'd +1 for:
Brett? |
Brett, If you agree with Yury, I will provide a patch with these tasks. |
Since getfullargspec is new in Python 3 and inspect.signature fundamentally improves things in Python 3 due to Argument Clinic I would say go ahead and code deprecate getfullargspec (we can do a DeprecationWarning for 3.5 and 3.6 and remove in 3.7; people needing compatibility can just use getargspec). As for getargspec, it was already deprecated so just leave it deprecated and update its message to say to use inspect.signature. As for keeping track of this stuff, Stéphane, as part of the test that makes sure the warning is raised, add to that test -- don't need a separate method -- some code that will fail if the function exists in Python 3.7 or later. |
Need your feedback for this patch Thank you |
Note that getargspec() depends on getfullargspec() so deprecating the latter *will* cause issues for single-source code (unless they switch to using the funcsigs backport). |
Nick, good catch. OK, let's just deprecate it in the docs for 3.5, so people (hopefully) will not write new code with it. |
+1 to doc deprecation and adding a DeprecationWarning for 3.5. |
@larry Hasting: If you check my patch, it's the case where I modify the @yury Selivanov, @nick Coghlan, @brett Cannon: From your point of views, @brett Cannon: In the current patch, I implemented a test with the I propose to follow the solution of @yury Selinanov, just deprecate the Are you agree? Thanks |
Please see the new patch. So it's time to deprecate getargspec with a warning (was softly deprecated in 3.0). getfullargspec() and getcallargs() deprecation is documented. I also want to deprecate formatargspec() and formatargvalues(), but Signature does not provide equivalents. Should we add them? |
New changeset 3a5fec5e025d by Yury Selivanov in branch 'default': |
Just a minor comment on the patch: + warnings.warn("inspect.getargspec() is deprecated, " Can you also add "stacklevel=2"? |
New changeset 666e5b554f32 by Yury Selivanov in branch 'default': |
New changeset 621e98bfc74b by Yury Selivanov in branch 'default': |
Thanks Berker! |
I'm copying/pasting my latest commit message on this issue here: """Add a note about deprecating old inspect APIs to whatsnew. Also, deprecate formatargspec, formatargvalues, and getargvalues In 3.6 we will remove 'getargsspec' function (was deprecated since Also, it is worth noting, that Signature API does not provide 100% |
It should be properly noted that the API isn't going to be actually removed anytime soon. Also I think issuing a warning about this was a mistake. For software that wants to stay compatible with both Python 2 and 3 it's basically useless. |
My last comment was in reference to getfullargspec, which is, as far as I understand, not going to be deprecated until after 3.7. |
I'm confused: the discussion here is mostly about updating docs to note deprecation. Then at the very end, is an off-hand remark about removing getargspec. The docs for getargspec currently read, "This function will be removed in Python 3.6." Why? We keep all sorts of old APIs for the sake of backward compatibility, why is this one different? |
getargspec was deprecated since 3.0. Besides that, it returns incomplete information about function parameters: keyword-only parameters won't be introspected at all for instance. Migration path is very simple and clear -- just use getfullargspec (almost 100% backwards compatible), which won't be removed probably till Python 4. |
The thing is, we've adopted a policy that if something exists in python2.7 we shouldn't delete it in python3 until after 2.7 is officially out of maintenance (at the earliest), in order to facilitate single-source porting to python3. That policy was adopted relatively recently, after the deprecation warning mentioning 3.6 was added in this issue, as I recall it. |
This is the situation I am in: coverage.py uses getargspec in a very simple way in its tooling. I support 2.7 and 3.5, so I have to do this:
It seems like needless churn. |
In this case we better resurrect getargspec(). Here's an issue for that: bpo-25486 |
I think it was me who submitted this code to coverage.py.. :) It might be worthwhile to keep it anyways, as getfullargspec uses the signature API, which supports a wider range of callables. |
Well, here is a feedback about lost functionality. inspect.getcallargs had a very nice property that it automatically bound the first argument to the instance of bound methods. It seems I have no general way to do it with Signature.bind. Of course I can put
afterwards, but theoretically, the argument doesn't have to be called 'self'. And anyway, I would like something that works seamlessly with bound methods and ordinary functions. |
Please open a new issue for that observation/request. |
Noting for the record, as the general way of querying an unbound method for the name of the first parameter and adding it to the bound arguments: def add_instance_arg(callable, bound_args):
try:
self = callable.__self__
func = callable.__func__
except AttributeError:
return # Not a bound method
unbound_sig = inspect.signature(func)
for name in unbound_sig.parameters:
bound_args.arguments[name] = self
break >>> method = C().method
>>> sig = inspect.signature(method)
>>> sig
<Signature (arg)>
>>> args = sig.bind(1)
>>> args
<BoundArguments (arg=1)>
>>> add_instance_arg(method, args)
>>> args
<BoundArguments (arg=1, self=<__main__.C object at 0x7f07ab719668>)> |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: