Skip to content

Conversation

caolonghao
Copy link
Contributor

@caolonghao caolonghao commented Oct 5, 2022

PR types

Others

PR changes

Others

Describe

Add escape symbol to some strings
在字符串注释前添加自动转义符号,添加原因见:cattidea/paddle-flake8-project#66#46752 (comment)

Related Links:

Flake8 tracking issue: #46039
配置文件更新: #46753
Fix: cattidea/paddle-flake8-project#66

@caolonghao caolonghao changed the title [CodeStyle][W605] Add escape symbol to some strings [CodeStyle][W605] Add escape symbols to some strings Oct 5, 2022
@paddle-bot
Copy link

paddle-bot bot commented Oct 5, 2022

你的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 Oct 5, 2022
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.

辛苦了,这个错误码需要修改的地方还是蛮多的,有一些小的细节可能需要调整下~

@@ -35,7 +35,7 @@ def get_all_paddle_file(rootPath):
def get_all_uts(rootPath):
all_uts_paddle = '%s/build/all_uts_paddle' % rootPath
os.system(
'cd %s/build && ctest -N -V | grep -Ei "Test[ \t]+#" | grep -oEi "\w+$" > %s'
r'cd %s/build && ctest -N -V | grep -Ei "Test[ \t]+#" | grep -oEi "\w+$" > %s'
Copy link
Member

Choose a reason for hiding this comment

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

这里在 Python runtime 是认为不等价的,但在 grep 看来是等价的,更多讨论见:cattidea/paddle-flake8-project#66 (comment)

(不用回复,这里只是链接下之前的讨论)

@@ -211,7 +211,7 @@ def convert_op_proto_into_mlir(op_descs):
dst_dialect_file = "../../paddle/infrt/dialect/pd/ir/pd_ops.td"

# 1. Head files
comment_ = "/*===- TableGen'source file -----------------------------------------------===*\\\n\
comment_ = r"/*===- TableGen'source file -----------------------------------------------===*\\\n\
Copy link
Member

@SigureMo SigureMo Oct 5, 2022

Choose a reason for hiding this comment

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

这里因为 '\n' 的存在也不是等价的,最后生成的代码文本里就会出现一堆 '\n' 😂,这里建议将左下角的 '\*===' 手动转义改为 '\\*===' 吧,就不加 r

下面的文件同~

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改~

Copy link
Member

Choose a reason for hiding this comment

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

好哒~等过完 CI 我再看下~

caolonghao and others added 2 commits October 5, 2022 23:30
@SigureMo SigureMo self-requested a review October 5, 2022 15:45
@@ -26,7 +26,7 @@ def attention(query,
key_padding_mask=None,
attn_mask=None,
name=None):
"""
r"""
Copy link
Member

Choose a reason for hiding this comment

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

image

这里因为 docstring 变动触发了这个示例代码的运行,这个示例代码我本地也跑不通,需要过两天讨论下如何解决

Copy link
Contributor Author

Choose a reason for hiding this comment

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

了解

Copy link
Member

Choose a reason for hiding this comment

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

这个要不先回撤掉这一个修改,在另外一个 PR 里单独修复这一个?这样能确保其余部分是能够正常过 CI 的,另外一个 PR 里再单独考虑怎么做

@caolonghao @luotao1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的,我先改改

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SigureMo 奇怪,这里我改回去了还是过不了CI,感觉像是只要出现了doc变化可能就会出现。Static-Check似乎需要approval
image

Copy link
Contributor

Choose a reason for hiding this comment

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

只要出现了doc变化可能就会出现。Static-Check似乎需要approval

对的,等其他流水线过后,Static-Check会进行approve豁免

@SigureMo SigureMo self-requested a review October 6, 2022 08:53
@luotao1 luotao1 self-assigned this Oct 10, 2022
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.

想问下为什么有的注释要加r,有的注释不需要呢?可以不加么?

@SigureMo
Copy link
Member

想问下为什么有的注释要加r,有的注释不需要呢?可以不加么?

是这样的,对于 Python 「字符串」,如果其中包含转义序列如 '\n''\r''\\' 这样的是正常的转义序列,所以说在字符串里表达「文本」 \ 其实应该写成 '\\',但 Python 字符串提供了 r 前缀能够使我们直接书写原始字符串(raw string),也就是书写的字符串和想表达的「文本」一致,不需要手动转义

同样,很多 docstring 里因为需要书写公式的缘故,使用了 \ 来进行 LaTeX 数学公式转义,如 \log,但这里的数学公式里的 \ 其实要求是在 Python 字符串上先转义一遍,也就是 '\\',如果这样的话,在书写数学公式时将会出现大量 '\\',非常不易读,而且不能直接 copy 到中文文档里(中文文档写的就是纯「文本」,而不是「字符串」,不需要转义),比如 \log\ (x) 将会需要在「字符串」里写成 '\\log\\ (x)',为了避免这一问题,其实是比较推荐在所有包含 LaTeX 数学公式的 docstring 上都加上 r 前缀以自动转义,这样我们只需要写成 r'\log\ (x)' 即可

关于一些不加还是会正确显示的文档,其实这是 Python 对这些错误的转义序列自动进行了转义,如 '\log\ (x)' == '\\log\\ (x)',因为 '\l''\ ' 都不是有效的转义序列,因此 Python 会在这些地方自动进行转义,但这不是推荐的(使用了隐式的行为),flake8 会帮助我们发现这些潜在的问题,可以让我们明确一个 '\' 到底是想表达纯文本 \ 还是转义符号 '\'

一些前置讨论可见 cattidea/paddle-flake8-project#66

@SigureMo
Copy link
Member

@caolonghao PR-CI-Windows 挂掉了,应该手动 re-run 下就可以过了~

luotao1
luotao1 previously approved these changes Oct 12, 2022
XiaoguangHu01
XiaoguangHu01 previously approved these changes Oct 19, 2022
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.

LGM

@luotao1
Copy link
Contributor

luotao1 commented Oct 19, 2022

需要解决下冲突

@caolonghao caolonghao dismissed stale reviews from XiaoguangHu01 and luotao1 via 3eb02a3 October 19, 2022 04:11
@@ -37,7 +37,7 @@ def attention(query,

.. math::

result = softmax(\frac{ Q * K^T }{\sqrt{d}}) * V
result = softmax(\frac{ Q * K^T }{\\sqrt{d}}) * V
Copy link
Member

Choose a reason for hiding this comment

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

这个应该也可以在前面直接加 r 来解决吧?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

呃,我在python runtime中测试,这部分字符串加 r 与不加 r 并不等价。按理说注释应该不影响,但是因为不知道会不会引起CI报错就先采用的这样保守的修改方式。

Copy link
Member

Choose a reason for hiding this comment

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

喔喔我没注意到这是那个会引起示例代码错误的字符串,这个可以先回撤掉,之后单独一个 PR 修改即可

Copy link
Member

Choose a reason for hiding this comment

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

之后单独一个 PR 修改即可

#47152 正在将这个 API 从 incubate 移出去,应该能够修复这里示例代码的问题,这处修复可以等该 PR merge 后再做

PR-CI-Build 貌似卡住了,导致其余三个也卡住了,re-run 下估计就可以过了,Kunlun 和 APPROVAL 最好也 re-run 下

@luotao1 luotao1 merged commit e1c0461 into PaddlePaddle:develop Oct 20, 2022
@caolonghao caolonghao deleted the W605/fix branch October 24, 2022 07:09
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.

[W605] invalid escape sequence ‘x’
4 participants