[CodeStyle][py2][py311] replace deprecated inspect.getargspec
with inspect.getfullargspec
#48218
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.
PR types
Others
PR changes
Others
Describe
inspect.getargspec
1 在 Python 3.0 已经标记为 deprecated 了,并已于 Python 3.11 移除2,因此已有的inspect.getargspec
可能成为支持 Python 3.11 的阻碍Python 3.0+ 的推荐是使用
inspect.getfullargspec
3 来替代inspect.getargspec
1,为了同时兼容 Python2 和 Python3 目前有一些代码对此做了处理,由于现在 Paddle 已经不再支持 Python24,因此这些处理可以移除,直接使用inspect.getfullargspec
即可inspect.getargspec
和inspect.getfullargspec
同样以 namedtuple 形式返回函数的参数,只不过后者比前者返回结果多一些,比如 keyword-only 参数和类型注解,前者在传入包含 keyword-only 参数或类型注解的函数时会报错inspect.getargspec
1 ->ArgSpec(args, varargs, keywords, defaults)
inspect.getfullargspec
3 ->FullArgSpec(args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations)
目前的
inspect.getargspec
用例均可使用inspect.getfullargspec
直接替换Footnotes
inspect — Inspect live objects - inspect.getargspec (Python 3.10 docs) ↩ ↩2 ↩3
What’s New In Python 3.11 - Removed ↩
inspect — Inspect live objects - inspect.getfullargspec (Python 3.10 docs) ↩ ↩2
[CodeStyle] Legacy python code cleanup tracking issue #46837 ↩