{Core} Python 3.11: Remove uses of deprecated inspect.getargspec#24111
Open
{Core} Python 3.11: Remove uses of deprecated inspect.getargspec#24111
Conversation
inspect.getargspec has been deprecated since 3.0 in favor of its replacement inspect.getfullargspec.
|
Thank you for your contribution mdboom! We will review the pull request and get back to you soon. |
Collaborator
|
remove deprecated dependencies on test |
Author
|
Speaking to @iritkatriel in another forum, it sounds like the most future-proof option is to use |
Author
Sorry, is this a request of me? I'm not sure I understand. |
7 tasks
Member
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
jiasli
reviewed
Jul 21, 2023
| def _auth_callback_compat(self, server, resource, scope, scheme): | ||
| return self._user_callback(server, resource, scope) \ | ||
| if len(inspect.getargspec(self._user_callback).args) == 3 \ | ||
| if len(inspect.signature(self._user_callback).parameters) == 3 \ |
Member
There was a problem hiding this comment.
This is not equivalent to the original code if self._user_callback contains *args and **kwargs, since signature's result includes *args (kind: VAR_POSITIONAL) and **kwargs (kind: VAR_KEYWORD) in parameters, but getargspec's result has dedicated varargs, keywords elements for them:
import inspect
def testfunc(a=1, b=2, *args, **kwargs):
pass
print(len(inspect.getfullargspec(testfunc).args))
print(inspect.getfullargspec(testfunc).args)
print(len(inspect.signature(testfunc).parameters))
print(inspect.signature(testfunc).parameters)Output:
2
['a', 'b']
4
OrderedDict([('a', <Parameter "a=1">), ('b', <Parameter "b=2">), ('args', <Parameter "*args">), ('kwargs', <Parameter "**kwargs">)])
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
inspect.getargspec has been deprecated since 3.0 in favor of its replacement inspect.getfullargspec.
This does change "vendored" code, and I couldn't find where that may require special treatment, if at all.
There is one other use of
inspect.getargspecthat is retained for backward compatibility with Python 2 that I didn't touch, but in reality that clause could also probably be removed since Python 2 is no longer supported.Related command
All
azcommands.Description
Another step on the road to Python 3.11 compatibility. (See also #24109)
Testing Guide
This checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.