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

[xdoctest][task 330] reformat example code with google style in python/paddle/base/data_feed_desc.py #57137

Merged
merged 9 commits into from
Sep 12, 2023
150 changes: 75 additions & 75 deletions python/paddle/base/data_feed_desc.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ class DataFeedDesc:

>>> import paddle.base as base
>>> with open("data.proto", "w") as f:
... f.write('name: "MultiSlotDataFeed"')
... f.write('batch_size: 2')
... f.write('multi_slot_desc {')
... f.write(' slots {')
... f.write(' name: "words"')
... f.write(' type: "uint64"')
... f.write(' is_dense: false')
... f.write(' is_used: true')
... f.write(' }')
... f.write(' slots {')
... f.write(' name: "label"')
... f.write(' type: "uint64"')
... f.write(' is_dense: false')
... f.write(' is_used: true')
... f.write(' }')
... f.write('name: "MultiSlotDataFeed"\\n')
Copy link
Member

Choose a reason for hiding this comment

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

咦?为啥要 \\n 呀,\\n 最后呈现的不是 \n 么?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image 我在本地用 `\n` 跑不过嘞

Copy link
Member

@SigureMo SigureMo Sep 12, 2023

Choose a reason for hiding this comment

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

我这边试了下可以过呀,直接使用 convert-doctest doctest python/paddle/base/data_feed_desc.py

我这边直接改好啦

Copy link
Member

Choose a reason for hiding this comment

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

唔,离谱,CI 报的错和你一样

image

@megemini doctest 怎么把 \n 识别成换行了,唔,奇怪

Copy link
Member

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.

convert-doctest 和 CI 提取 docstring 原理不同,一个是字符串裁剪,一个是运行时通过 __doc__ 获取,所以 \n 自然就是换行了,这里用 r raw string 即可两者都能跑(大概?看看 CI 结果)

Copy link
Contributor

Choose a reason for hiding this comment

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

正解! \n 在 docstring 中是要用 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.

感谢大佬们!学到嘞~

... f.write('batch_size: 2\\n')
... f.write('multi_slot_desc {\\n')
... f.write(' slots {\\n')
... f.write(' name: "words"\\n')
... f.write(' type: "uint64"\\n')
... f.write(' is_dense: false\\n')
... f.write(' is_used: true\\n')
... f.write(' }\\n')
... f.write(' slots {\\n')
... f.write(' name: "label"\\n')
... f.write(' type: "uint64"\\n')
... f.write(' is_dense: false\\n')
... f.write(' is_used: true\\n')
... f.write(' }\\n')
... f.write('}')
>>> data_feed = base.DataFeedDesc('data.proto')

Expand Down Expand Up @@ -101,21 +101,21 @@ def set_batch_size(self, batch_size):

>>> import paddle.base as base
>>> with open("data.proto", "w") as f:
... f.write('name: "MultiSlotDataFeed"')
... f.write('batch_size: 2')
... f.write('multi_slot_desc {')
... f.write(' slots {')
... f.write(' name: "words"')
... f.write(' type: "uint64"')
... f.write(' is_dense: false')
... f.write(' is_used: true')
... f.write(' }')
... f.write(' slots {')
... f.write(' name: "label"')
... f.write(' type: "uint64"')
... f.write(' is_dense: false')
... f.write(' is_used: true')
... f.write(' }')
... f.write('name: "MultiSlotDataFeed"\\n')
... f.write('batch_size: 2\\n')
... f.write('multi_slot_desc {\\n')
... f.write(' slots {\\n')
... f.write(' name: "words"\\n')
... f.write(' type: "uint64"\\n')
... f.write(' is_dense: false\\n')
... f.write(' is_used: true\\n')
... f.write(' }\\n')
... f.write(' slots {\\n')
... f.write(' name: "label"\\n')
... f.write(' type: "uint64"\\n')
... f.write(' is_dense: false\\n')
... f.write(' is_used: true\\n')
... f.write(' }\\n')
... f.write('}')
>>> data_feed = base.DataFeedDesc('data.proto')
>>> data_feed.set_batch_size(128)
Expand All @@ -141,21 +141,21 @@ def set_dense_slots(self, dense_slots_name):

>>> import paddle.base as base
>>> with open("data.proto", "w") as f:
... f.write('name: "MultiSlotDataFeed"')
... f.write('batch_size: 2')
... f.write('multi_slot_desc {')
... f.write(' slots {')
... f.write(' name: "words"')
... f.write(' type: "uint64"')
... f.write(' is_dense: false')
... f.write(' is_used: true')
... f.write(' }')
... f.write(' slots {')
... f.write(' name: "label"')
... f.write(' type: "uint64"')
... f.write(' is_dense: false')
... f.write(' is_used: true')
... f.write(' }')
... f.write('name: "MultiSlotDataFeed"\\n')
... f.write('batch_size: 2\\n')
... f.write('multi_slot_desc {\\n')
... f.write(' slots {\\n')
... f.write(' name: "words"\\n')
... f.write(' type: "uint64"\\n')
... f.write(' is_dense: false\\n')
... f.write(' is_used: true\\n')
... f.write(' }\\n')
... f.write(' slots {\\n')
... f.write(' name: "label"\\n')
... f.write(' type: "uint64"\\n')
... f.write(' is_dense: false\\n')
... f.write(' is_used: true\\n')
... f.write(' }\\n')
... f.write('}')
>>> data_feed = base.DataFeedDesc('data.proto')
>>> data_feed.set_dense_slots(['words'])
Expand Down Expand Up @@ -187,21 +187,21 @@ def set_use_slots(self, use_slots_name):

>>> import paddle.base as base
>>> with open("data.proto", "w") as f:
... f.write('name: "MultiSlotDataFeed"')
... f.write('batch_size: 2')
... f.write('multi_slot_desc {')
... f.write(' slots {')
... f.write(' name: "words"')
... f.write(' type: "uint64"')
... f.write(' is_dense: false')
... f.write(' is_used: true')
... f.write(' }')
... f.write(' slots {')
... f.write(' name: "label"')
... f.write(' type: "uint64"')
... f.write(' is_dense: false')
... f.write(' is_used: true')
... f.write(' }')
... f.write('name: "MultiSlotDataFeed"\\n')
... f.write('batch_size: 2\\n')
... f.write('multi_slot_desc {\\n')
... f.write(' slots {\\n')
... f.write(' name: "words"\\n')
... f.write(' type: "uint64"\\n')
... f.write(' is_dense: false\\n')
... f.write(' is_used: true\\n')
... f.write(' }\\n')
... f.write(' slots {\\n')
... f.write(' name: "label"\\n')
... f.write(' type: "uint64"\\n')
... f.write(' is_dense: false\\n')
... f.write(' is_used: true\\n')
... f.write(' }\\n')
... f.write('}')
>>> data_feed = base.DataFeedDesc('data.proto')
>>> data_feed.set_use_slots(['words'])
Expand Down Expand Up @@ -230,21 +230,21 @@ def desc(self):

>>> import paddle.base as base
>>> with open("data.proto", "w") as f:
... f.write('name: "MultiSlotDataFeed"')
... f.write('batch_size: 2')
... f.write('multi_slot_desc {')
... f.write(' slots {')
... f.write(' name: "words"')
... f.write(' type: "uint64"')
... f.write(' is_dense: false')
... f.write(' is_used: true')
... f.write(' }')
... f.write(' slots {')
... f.write(' name: "label"')
... f.write(' type: "uint64"')
... f.write(' is_dense: false')
... f.write(' is_used: true')
... f.write(' }')
... f.write('name: "MultiSlotDataFeed"\\n')
... f.write('batch_size: 2\\n')
... f.write('multi_slot_desc {\\n')
... f.write(' slots {\\n')
... f.write(' name: "words"\\n')
... f.write(' type: "uint64"\\n')
... f.write(' is_dense: false\\n')
... f.write(' is_used: true\\n')
... f.write(' }\\n')
... f.write(' slots {\\n')
... f.write(' name: "label"\\n')
... f.write(' type: "uint64"\\n')
... f.write(' is_dense: false\\n')
... f.write(' is_used: true\\n')
... f.write(' }\\n')
... f.write('}')
>>> data_feed = base.DataFeedDesc('data.proto')
>>> print(data_feed.desc())
Expand Down