Skip to content
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

[CodeStyle][py2][py311] replace deprecated inspect.getargspec with inspect.getfullargspec #48218

Merged
merged 2 commits into from
Nov 22, 2022

Conversation

SigureMo
Copy link
Member

@SigureMo SigureMo commented Nov 22, 2022

PR types

Others

PR changes

Others

Describe

inspect.getargspec1 在 Python 3.0 已经标记为 deprecated 了,并已于 Python 3.11 移除2,因此已有的 inspect.getargspec 可能成为支持 Python 3.11 的阻碍

Python 3.0+ 的推荐是使用 inspect.getfullargspec3 来替代 inspect.getargspec1,为了同时兼容 Python2 和 Python3 目前有一些代码对此做了处理,由于现在 Paddle 已经不再支持 Python24,因此这些处理可以移除,直接使用 inspect.getfullargspec 即可

inspect.getargspecinspect.getfullargspec 同样以 namedtuple 形式返回函数的参数,只不过后者比前者返回结果多一些,比如 keyword-only 参数和类型注解,前者在传入包含 keyword-only 参数或类型注解的函数时会报错

  • inspect.getargspec1 -> ArgSpec(args, varargs, keywords, defaults)
  • inspect.getfullargspec3 -> FullArgSpec(args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations)

目前的 inspect.getargspec 用例均可使用 inspect.getfullargspec 直接替换

Footnotes

  1. inspect — Inspect live objects - inspect.getargspec (Python 3.10 docs) 2 3

  2. What’s New In Python 3.11 - Removed

  3. inspect — Inspect live objects - inspect.getfullargspec (Python 3.10 docs) 2

  4. [CodeStyle] Legacy python code cleanup tracking issue #46837

@paddle-bot
Copy link

paddle-bot bot commented Nov 22, 2022

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added contributor External developers status: proposed labels Nov 22, 2022
@SigureMo SigureMo changed the title [WIP][CodeStyle][py2] replace deprecated inspect.getargspec with inspect.getfullargspect [WIP][CodeStyle][py2] replace deprecated inspect.getargspec with inspect.getfullargspect Nov 22, 2022
@SigureMo SigureMo changed the title [WIP][CodeStyle][py2] replace deprecated inspect.getargspec with inspect.getfullargspect [WIP][CodeStyle][py2] replace deprecated inspect.getargspec with inspect.getfullargspect Nov 22, 2022
@SigureMo SigureMo changed the title [WIP][CodeStyle][py2] replace deprecated inspect.getargspec with inspect.getfullargspect [WIP][CodeStyle][py2][py311] replace deprecated inspect.getargspec with inspect.getfullargspect Nov 22, 2022
@SigureMo SigureMo changed the title [WIP][CodeStyle][py2][py311] replace deprecated inspect.getargspec with inspect.getfullargspect [WIP][CodeStyle][py2][py311] replace deprecated inspect.getargspec with inspect.getfullargspec Nov 22, 2022
@luotao1 luotao1 self-assigned this Nov 22, 2022
@luotao1 luotao1 changed the title [WIP][CodeStyle][py2][py311] replace deprecated inspect.getargspec with inspect.getfullargspec [CodeStyle][py2][py311] replace deprecated inspect.getargspec with inspect.getfullargspec Nov 22, 2022
@luotao1 luotao1 merged commit d6b94d2 into PaddlePaddle:develop Nov 22, 2022
@SigureMo SigureMo deleted the py2/py11/fix/getargspec branch November 22, 2022 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants