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][UP030][UP031][UP032] using f-string #52062

Merged
merged 5 commits into from
Mar 31, 2023

Conversation

Liyulingyue
Copy link
Contributor

@Liyulingyue Liyulingyue commented Mar 23, 2023

PR types

Others

PR changes

Others

Describe

#51729 case 14 15 16
ruff rules

  • UP030: Use implicit references for positional format fields,'{0}{1}'.format(a,b) to '{}{}'.format(a,b),虽然这样更为简洁,但是从代码易读性角度考虑,不建议引入这条规则,但结合32,该规则必须引入。
  • UP031:Use format specifiers instead of percent format,"%s%s" % to '{}{}'.format(),两者效果相同,但是使用后者无需指定填充类型,更为简便。
  • UP032:使用f string 代替 format。f{obj} = ‘{}’.format(obj),f string在py3.6后引入,相比原先的'%s'和format,这种方式可读性更好,并且不易出错。

是否可以引入本 rule:✅ 可引入。
是否可引入自动修复:✅ 可引入(UP032部分内容仍需手动)。

@paddle-bot
Copy link

paddle-bot bot commented Mar 23, 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.

@paddle-bot paddle-bot bot added contributor External developers status: proposed labels Mar 23, 2023
@Liyulingyue Liyulingyue changed the title [CodeStyle][UP030][UP031][UP032] [CodeStyle][UP030][UP031][UP032] using f-string Mar 23, 2023
@SigureMo
Copy link
Member

SigureMo commented Mar 25, 2023

麻烦解决一下冲突,这个 PR 尽可能这周末合了吧,不然不知道要冲突到啥时候(解决完我再 review,之前那个 1000+ 文件的要看吐了)

@luotao1
Copy link
Contributor

luotao1 commented Mar 28, 2023

请解决下冲突

SigureMo
SigureMo previously approved these changes Mar 28, 2023
Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

LGTM

目前 %s -> .format 不是 100% 的,是因为对于 "%s" % var 来说 var 是 tuple/dict/单个值所需要的转写方式完全不一样,因此没办法 100% 转写,Ruff 0.0.258 ( astral-sh/ruff#3600 )对此有所改进,但大多数 case 是没办法解决的,因此这些无法转写是正常的

目前 .format -> f-string 不是 100% 的,这是由于 Python 机制的问题,Python f-string 里对于部分表达式是不支持的,这个可能在 PEP 701 – Syntactic formalization of f-strings 有改进,但要等到 Python 3.12

Copy link
Member

Choose a reason for hiding this comment

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

怎么多了些无关的改动?

Co-authored-by: Liyulingyue <[email protected]>
SigureMo
SigureMo previously approved these changes Mar 30, 2023
Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

LGTM

等 CI 过了且无冲突就可以 merge 了

Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

LGTM

已经把 #52060 遗留的 test_slice 解决

另附引入本 rule 最早期的动机:#47549 (comment)

@luotao1 luotao1 merged commit 40e4f5a into PaddlePaddle:develop Mar 31, 2023
@Liyulingyue Liyulingyue deleted the up313233 branch April 6, 2023 13:45
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