Repository navigation
[CodeStyle][PLC3002][PLE1205] simplify lambda and add missing placeholder to logger template - #52133
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
|
emmm,你可能理解有误,我要的官方文档是指 Python 对于这些语法、函数的文档(包括 PEP 这种较为权威的文档,最差也得是 StackOverflow 这种高质量的讨论),Linter 本身(Ruff 也好,Ruff 所实现的 PyLint 原规则也好)都认为自己做的有道理,这些文档是没有太大意义的,这里的调研主要是指你对这个改动是如何理解的,是如何去评价 Linter 本身的,引用 Linter 本身的文档并不能得到多少有用的信息 |
| x = fluid.dygraph.to_variable(x) | ||
|
|
||
| y = (lambda x, y: x + y)(x, x) | ||
| out = (lambda x: paddle.mean(x))(y) |
There was a problem hiding this comment.
根据文件名和动转静的特殊性,这里明显就是为了测试 lambda 语法是否能够正确转写的,因此不可以修改,该 rule 不适合引入
There was a problem hiding this comment.
以下是一些关于 lambdas 的讨论:
https://stackoverflow.com/questions/890128/how-are-lambdas-useful/890188
我的看法是,像(lambda x: x**2)(y)这种完全可以简化, 使用 lambda 会让阅读变得复杂
所以个人建议是使用[tool.ruff.per-file-ignores]排除当前文件, 来应用该 rule
There was a problem hiding this comment.
所以个人建议是使用[tool.ruff.per-file-ignores]排除当前文件, 来应用该 rule
可以
| getattr(msg, field.name), name, configs | ||
| ) | ||
| else: | ||
| logger.debug("not message:", name) |
There was a problem hiding this comment.
该 rule 再多调研一下吧,如果调研结果合适可以引入
There was a problem hiding this comment.
There was a problem hiding this comment.
对日志输出优化
这里并不是优化,而是避免出现错误的使用方式,目前代码里的使用方式是错误的
应引用文档 https://docs.python.org/3/howto/logging.html#logging-variable-data ,参数数量 > 占位符数量,会触发运行时错误
本 rule 可引入,可避免 bug
本 rule 无自动修复功能,需要开发者手动修复
|
辛苦解决下冲突 |
|
我好像点到了什么,怎么被 dismissed 了 |
Paddle 的设置就是新的非空 commit 会取消已有 approval,这个没关系的 |
|
辛苦解决下冲突 |
…3002 # Conflicts: # pyproject.toml
Done |

PR types
Others
PR changes
Others
Describe
PLC3002
参考文档pylint unnecessary-direct-lambda-call / C3002
对 Lambda 表达式进行简化
PLE1205
参考文档pylint logging-too-many-args / E1205
对日志输出优化
是否可以引入本 rule:✅ 如上所述,可以引入
是否可引入自动修复:❌手动修复
Related links
introducing ruffcommunity#412