homepage

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.

classification
Title: inspect: Deprecate getfullargspec?
Type: enhancement Stage: resolved
Components: Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: 25486 Superseder:
Assigned To: Nosy List: berker.peksag, brett.cannon, hugovk, larry, matrixise, ncoghlan, nedbat, python-dev, r.david.murray, untitaker, veky, yselivanov
Priority: normal Keywords: patch

Created on 2014年01月29日 17:00 by yselivanov, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue20438_deprecate_inspect-getfullargspec.patch matrixise, 2014年04月15日 15:47 review
issue20438_deprecate_inspect_getfullargspec-2.patch matrixise, 2014年04月15日 19:28 review
getargspec.diff yselivanov, 2015年05月21日 18:57 review
Pull Requests
URL Status Linked Edit
PR 122 merged mbussonn, 2017年02月15日 16:54
PR 243 merged berker.peksag, 2017年02月22日 22:08
PR 244 merged berker.peksag, 2017年02月22日 22:10
PR 28618 merged hugovk, 2021年09月29日 12:48
Messages (40)
msg209658 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2014年01月29日 17:00
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".
msg209664 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2014年01月29日 18:28
I vote deprecation with no stated plans of removal
msg209665 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2014年01月29日 18:28
Although I say do it in 3.5.
msg209692 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2014年01月29日 23:17
As Brett said - let's do a documented deprecation in 3.5.
msg216317 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2014年04月15日 15:47
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
msg216318 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2014年04月15日 15:47
Here is the output of my test:
> ./python3.5 -Wd test.py
test.py:9: DeprecationWarning: Deprecated
 warnings.warn('Deprecated', DeprecationWarning)
/private/tmp/python/lib/python3.5/inspect.py:955: DeprecationWarning: Use inspect.signature() instead of inspect.getfullargspec()
 warnings.warn("Use inspect.signature() instead of inspect.getfullargspec()", DeprecationWarning)
FullArgSpec(args=[], varargs='args', varkw='kwargs', defaults=None, kwonlyargs=[], kwonlydefaults=None, annotations={})
msg216327 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2014年04月15日 16:16
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.
msg216328 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2014年04月15日 16:20
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)?
msg216333 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2014年04月15日 16:40
Just one thing, how do you work for the deprecation?
1. you deprecate in the doc for 3.5?
2. you deprecate in the code for 3.6?
3. you remove the code in 3.7?
What's the strategy in this case or in general?
Thanks
msg216337 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2014年04月15日 16:58
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.
msg216339 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2014年04月15日 17:02
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?
msg216340 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2014年04月15日 17:07
I'd +1 for:
1. Deprecating getfullargsspec in docs;
2. Deprecating getargspec in docs and code (since it's an ancient and outdated API)
Brett?
msg216341 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2014年04月15日 17:09
Brett,
If you agree with Yury, I will provide a patch with these tasks.
msg216342 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2014年04月15日 17:28
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.
msg216365 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2014年04月15日 19:28
Need your feedback for this patch
Thank you
msg216385 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2014年04月15日 21:04
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).
msg216387 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2014年04月15日 21:20
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.
msg216621 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2014年04月16日 23:17
+1 to doc deprecation and adding a DeprecationWarning for 3.5.
msg217581 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2014年04月30日 08:09
@Larry Hasting: If you check my patch, it's the case where I modify the 
documentation and add a DeprecationWarning in the code.
@Yury Selivanov, @Nick Coghlan, @Brett Cannon: From your point of views, 
I need to propose a patch just for the documentation, I agree with that.
@Brett Cannon: In the current patch, I implemented a test with the 
python version. If the version is greater or equal than 3.7, in this 
case, I raise an exception.
I propose to follow the solution of @Yury Selinanov, just deprecate the 
function in the documentation and keep the check in the unit test for 
the version.
Are you agree?
Thanks
msg243777 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015年05月21日 18:57
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?
msg243835 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015年05月22日 15:39
New changeset 3a5fec5e025d by Yury Selivanov in branch 'default':
Issue 20438: Deprecate inspect.getargspec() and friends.
https://hg.python.org/cpython/rev/3a5fec5e025d 
msg243848 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2015年05月22日 19:42
Just a minor comment on the patch:
+ warnings.warn("inspect.getargspec() is deprecated, "
+ "use inspect.signature() instead", DeprecationWarning)
Can you also add "stacklevel=2"?
msg243850 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015年05月22日 20:09
New changeset 666e5b554f32 by Yury Selivanov in branch 'default':
Issue 20438: Adjust stacklevel of inspect.getargspec() warning.
https://hg.python.org/cpython/rev/666e5b554f32 
msg243851 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015年05月22日 20:28
New changeset 621e98bfc74b by Yury Selivanov in branch 'default':
Issue 20438: Add a note about deprecating old inspect APIs to whatsnew.
https://hg.python.org/cpython/rev/621e98bfc74b 
msg243852 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015年05月22日 20:28
Thanks Berker!
msg243853 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015年05月22日 20:30
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
functions. Since we are deprecating 'getfullargspec' function in
3.5 (documentation only, no DeprecationWarning), it makes sense
to also deprecate functions designed to be directly used with it.
In 3.6 we will remove 'getargsspec' function (was deprecated since
Python 3.0), and start raising DeprecationWarnings in other
'getarg*' family of functions. We can remove them in 3.7 or later.
Also, it is worth noting, that Signature API does not provide 100%
of functionality that deprecated APIs have. It is important to do
a soft deprecation of outdated APIs in 3.5 to gather users feedback,
and improve Signature object."""
msg250805 - (view) Author: Markus Unterwaditzer (untitaker) Date: 2015年09月15日 20:42
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.
msg250808 - (view) Author: Markus Unterwaditzer (untitaker) Date: 2015年09月15日 20:46
My last comment was in reference to getfullargspec, which is, as far as I understand, not going to be deprecated until after 3.7.
msg253434 - (view) Author: Ned Batchelder (nedbat) * (Python triager) Date: 2015年10月25日 19:44
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?
msg253436 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015年10月25日 21:13
> 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.
msg253473 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015年10月26日 13:38
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.
msg253475 - (view) Author: Ned Batchelder (nedbat) * (Python triager) Date: 2015年10月26日 14:39
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:
 try:
 getargspec = inspect.getfullargspec
 except AttributeError:
 getargspec = inspect.getargspec
 argspec = getargspec(function)
It seems like needless churn.
msg253500 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015年10月26日 20:34
> 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.
In this case we better resurrect getargspec(). Here's an issue for that: #25486 
msg253501 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015年10月26日 20:37
> 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:
 try:
 getargspec = inspect.getfullargspec
 except AttributeError:
 getargspec = inspect.getargspec
 argspec = getargspec(function)
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.
msg254892 - (view) Author: Vedran Čačić (veky) * Date: 2015年11月19日 09:49
> Also, it is worth noting, that Signature API does not provide 100%
of functionality that deprecated APIs have. It is important to do
a soft deprecation of outdated APIs in 3.5 to gather users feedback,
and improve Signature object.
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
 arguments['self'] = method.__self__
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.
msg254899 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015年11月19日 14:46
Please open a new issue for that observation/request.
msg282173 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2016年12月01日 13:20
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>)>
msg288334 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017年02月22日 05:45
New changeset 0899b9809547ec2894dcf88cf4bba732c5d47d0d by Berker Peksag in branch 'master':
bpo-28814: Undeprecate inadvertently deprecated inspect functions. (#122)
https://github.com/python/cpython/commit/0899b9809547ec2894dcf88cf4bba732c5d47d0d
msg290422 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2017年03月24日 23:50
New changeset 0246422b974b1a0c50dd30b0e1a1138674ef87a5 by Nick Coghlan (Berker Peksag) in branch '3.5':
bpo-28814: Undeprecate inadvertently deprecated inspect functions. (#122) (#244)
https://github.com/python/cpython/commit/0246422b974b1a0c50dd30b0e1a1138674ef87a5
msg290425 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2017年03月24日 23:50
New changeset 2197eac6104311472f200645bc844adb46444b10 by Nick Coghlan (Berker Peksag) in branch '3.6':
bpo-28814: Undeprecate inadvertently deprecated inspect functions. (#122) (#243)
https://github.com/python/cpython/commit/2197eac6104311472f200645bc844adb46444b10
History
Date User Action Args
2022年04月11日 14:57:57adminsetgithub: 64637
2021年09月29日 12:48:03hugovksetnosy: + hugovk

pull_requests: + pull_request26990
2017年03月24日 23:50:35ncoghlansetmessages: + msg290425
2017年03月24日 23:50:19ncoghlansetmessages: + msg290422
2017年02月22日 22:10:11berker.peksagsetpull_requests: + pull_request209
2017年02月22日 22:08:02berker.peksagsetpull_requests: + pull_request207
2017年02月22日 05:45:53berker.peksagsetmessages: + msg288334
2017年02月15日 16:54:27mbussonnsetpull_requests: + pull_request84
2016年12月01日 13:20:28ncoghlansetmessages: + msg282173
2015年11月19日 14:46:37r.david.murraysetmessages: + msg254899
2015年11月19日 09:49:18vekysetnosy: + veky
messages: + msg254892
2015年10月26日 20:37:11yselivanovsetmessages: + msg253501
2015年10月26日 20:34:21yselivanovsetdependencies: + Resurrect inspect.getargspec() in 3.6
messages: + msg253500
2015年10月26日 14:39:07nedbatsetmessages: + msg253475
2015年10月26日 13:38:53r.david.murraysetnosy: + r.david.murray
messages: + msg253473
2015年10月25日 21:13:47yselivanovsetmessages: + msg253436
2015年10月25日 19:44:15nedbatsetnosy: + nedbat
messages: + msg253434
2015年09月15日 20:46:52untitakersetmessages: + msg250808
2015年09月15日 20:42:14untitakersetnosy: + untitaker
messages: + msg250805
2015年05月22日 20:30:40yselivanovsetmessages: + msg243853
2015年05月22日 20:28:39yselivanovsetmessages: + msg243852
2015年05月22日 20:28:16python-devsetmessages: + msg243851
2015年05月22日 20:09:59python-devsetmessages: + msg243850
2015年05月22日 19:42:13berker.peksagsetnosy: + berker.peksag
messages: + msg243848
2015年05月22日 15:39:20yselivanovsetstatus: open -> closed
resolution: fixed
stage: resolved
2015年05月22日 15:39:03python-devsetnosy: + python-dev
messages: + msg243835
2015年05月21日 18:57:27yselivanovsetfiles: + getargspec.diff

messages: + msg243777
2014年04月30日 08:09:16matrixisesetmessages: + msg217581
2014年04月16日 23:17:25larrysetmessages: + msg216621
2014年04月15日 21:21:00yselivanovsetmessages: + msg216387
2014年04月15日 21:04:38ncoghlansetmessages: + msg216385
2014年04月15日 19:28:02matrixisesetfiles: + issue20438_deprecate_inspect_getfullargspec-2.patch

messages: + msg216365
2014年04月15日 17:28:29brett.cannonsetmessages: + msg216342
2014年04月15日 17:09:53matrixisesetmessages: + msg216341
2014年04月15日 17:07:30yselivanovsetmessages: + msg216340
2014年04月15日 17:02:52matrixisesetmessages: + msg216339
2014年04月15日 16:58:03brett.cannonsetmessages: + msg216337
2014年04月15日 16:40:49matrixisesetmessages: + msg216333
2014年04月15日 16:20:06yselivanovsetmessages: + msg216328
2014年04月15日 16:16:35brett.cannonsetmessages: + msg216327
2014年04月15日 15:47:48matrixisesetmessages: + msg216318
2014年04月15日 15:47:22matrixisesetfiles: + issue20438_deprecate_inspect-getfullargspec.patch

nosy: + matrixise
messages: + msg216317

keywords: + patch
2014年01月29日 23:17:58yselivanovsetversions: + Python 3.5, - Python 3.4
2014年01月29日 23:17:29ncoghlansetmessages: + msg209692
2014年01月29日 18:28:51brett.cannonsetmessages: + msg209665
2014年01月29日 18:28:28brett.cannonsetmessages: + msg209664
2014年01月29日 17:00:13yselivanovcreate

AltStyle によって変換されたページ (->オリジナル) /