-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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][PLC3002][PLE1205] simplify lambda and add missing placeholder to logger template #52133
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
emmm,你可能理解有误,我要的官方文档是指 Python 对于这些语法、函数的文档(包括 PEP 这种较为权威的文档,最差也得是 StackOverflow 这种高质量的讨论),Linter 本身(Ruff 也好,Ruff 所实现的 PyLint 原规则也好)都认为自己做的有道理,这些文档是没有太大意义的,这里的调研主要是指你对这个改动是如何理解的,是如何去评价 Linter 本身的,引用 Linter 本身的文档并不能得到多少有用的信息 |
@@ -37,8 +37,8 @@ def call_lambda_as_func(x): | |||
def call_lambda_directly(x): | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
根据文件名和动转静的特殊性,这里明显就是为了测试 lambda 语法是否能够正确转写的,因此不可以修改,该 rule 不适合引入
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
以下是一些关于 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
所以个人建议是使用[tool.ruff.per-file-ignores]排除当前文件, 来应用该 rule
可以
@@ -543,7 +543,7 @@ def set_table_config(msg, config_name, configs, index=0): | |||
getattr(msg, field.name), name, configs | |||
) | |||
else: | |||
logger.debug("not message:", name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
该 rule 再多调研一下吧,如果调研结果合适可以引入
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对日志输出优化
这里并不是优化,而是避免出现错误的使用方式,目前代码里的使用方式是错误的
应引用文档 https://docs.python.org/3/howto/logging.html#logging-variable-data ,参数数量 > 占位符数量,会触发运行时错误
本 rule 可引入,可避免 bug
本 rule 无自动修复功能,需要开发者手动修复
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
辛苦解决下冲突 |
我好像点到了什么,怎么被 dismissed 了 |
Paddle 的设置就是新的非空 commit 会取消已有 approval,这个没关系的 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
辛苦解决下冲突 |
…3002 # Conflicts: # pyproject.toml
Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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 ruff
community#412