-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Changes from 2 commits
d5777a2
7d5f55b
d0120e6
eb8fb2f
723b0f7
c4c0dd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,10 @@ select = [ | |
# "B030", | ||
"B032", | ||
# "B904", | ||
|
||
# Pylint | ||
"PLC3002", | ||
"PLE1205" | ||
] | ||
unfixable = [ | ||
"NPY001" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 以下是一些关于 lambdas 的讨论: 我的看法是,像 所以个人建议是使用 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
可以 |
||
y = x + x | ||
out = paddle.mean(y) | ||
|
||
return out | ||
|
||
|
@@ -48,8 +48,8 @@ def call_lambda_in_func(x): | |
|
||
add_func = lambda x: x + 1 | ||
|
||
y = paddle.mean((lambda x: F.relu(x))(x)) | ||
out = add_func(y) if y > 1 and y < 2 else (lambda x: x**2)(y) | ||
y = paddle.mean((F.relu(x))) | ||
out = add_func(y) if y > 1 and y < 2 else y**2 | ||
|
||
return out | ||
|
||
|
@@ -60,7 +60,7 @@ def call_lambda_with_ifExpr(x): | |
add_func = lambda x: x + 1 | ||
|
||
y = paddle.mean(x) | ||
out = add_func(y) if y or y < 2 else (lambda x: x**2)(y) | ||
out = add_func(y) if y or y < 2 else y**2 | ||
|
||
return out | ||
|
||
|
@@ -74,7 +74,7 @@ def call_lambda_with_ifExpr2(x): | |
|
||
# NOTE: y is Variable, but z<2 is python bool value | ||
z = 0 | ||
out = add_func(y) if y or z < 2 else (lambda x: x**2)(y) | ||
out = add_func(y) if y or z < 2 else y**2 | ||
|
||
return out | ||
|
||
|
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.
https://docs.python.org/3/howto/logging.html#optimization
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 无自动修复功能,需要开发者手动修复