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][UP005] replace deprecated unittest aliases #49522

Merged
merged 1 commit into from
Jan 6, 2023

Conversation

SigureMo
Copy link
Member

@SigureMo SigureMo commented Jan 3, 2023

PR types

Others

PR changes

Others

Describe

清理一些 unittest 模块弃用的 API 别名,相关 API 已经分别在 Python 3.1、3.2、3.5 弃用了1,将会在 Python 3.12 移除2

Deprecated alias Method Name Deprecated in
failUnless assertTrue() 3.1
failIf assertFalse() 3.1
failUnlessEqual assertEqual() 3.1
failIfEqual assertNotEqual() 3.1
failUnlessAlmostEqual assertAlmostEqual() 3.1
failIfAlmostEqual assertNotAlmostEqual() 3.1
failUnlessRaises assertRaises() 3.1
assert_ assertTrue() 3.2
assertEquals assertEqual() 3.2
assertNotEquals assertNotEqual() 3.2
assertAlmostEquals assertAlmostEqual() 3.2
assertNotAlmostEquals assertNotAlmostEqual() 3.2
assertRegexpMatches assertRegex() 3.2
assertRaisesRegexp assertRaisesRegex() 3.2
assertNotRegexpMatches assertNotRegex() 3.5

清理所使用的命令:

ruff --select=UP005 . --fix

Related links

Footnotes

  1. unittest — Unit testing framework - Deprecated aliases

  2. What’s New In Python 3.11 - Pending Removal in Python 3.12

@paddle-bot
Copy link

paddle-bot bot commented Jan 3, 2023

你的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.

@luotao1
Copy link
Contributor

luotao1 commented Jan 4, 2023

ruff --select=UP005 . --fix

是考虑集成ruff么?

@SigureMo
Copy link
Member Author

SigureMo commented Jan 4, 2023

是考虑集成ruff么?

这个我想在 ruff 基本把所有 pyupgrade 规则实现了(主要是 %s 转写和 f-string 转写)之后考虑一下1,因为 pyupgrade 引入时一次性改动太多了,不好 review,而 ruff 则可以逐个规则进行修复,另外 pyupgrade 实现的 %s 转写有一种很常见的 case 没有覆盖,会导致大量代码没有被转写,因此这里我想先等等 ruff 实现的效果

不过无论引入什么工具,这个 PR 应该都是会做的,因为这些 aliases 会在 Python 3.12 被移除

Footnotes

  1. 实现进展见 Implement pyupgrade astral-sh/ruff#827

@SigureMo SigureMo changed the title [WIP][CodeStyle][UP005] replace deprecated unittest aliases [CodeStyle][UP005] replace deprecated unittest aliases Jan 4, 2023
Copy link
Contributor

@luotao1 luotao1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@luotao1 luotao1 merged commit d00c2ca into PaddlePaddle:develop Jan 6, 2023
@SigureMo SigureMo deleted the UP005/fix/all branch January 6, 2023 05:34
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.

3 participants