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

Add docstring checker. #9848

Merged
merged 19 commits into from
May 28, 2018
Merged

Add docstring checker. #9848

merged 19 commits into from
May 28, 2018

Conversation

gongweibao
Copy link
Contributor

@gongweibao gongweibao requested a review from helinwang April 11, 2018 12:23
@gongweibao gongweibao changed the title [WIP]Add docstring checker. Add docstring checker. Apr 11, 2018
Copy link
Contributor

@panyx0718 panyx0718 left a comment

Choose a reason for hiding this comment

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

LG overall.

One important TODO is to check if our auto-doc generator can recognize the style requested by the pylint

For example, current we use
:param and :return:
instead of
Args and Returns

"""

def __init__(self):
from collections import defaultdict
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move import to the top?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

self.d['Raises'] = []
self.args = {} #arg_name->arg_type

def get_level(self, string, indent=' '):
Copy link
Contributor

Choose a reason for hiding this comment

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

Have we agreed that the indent is 4, instead of 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Come from google python style guide.
And now almost all of the comments use 4 spaces indention.

Copy link
Contributor

Choose a reason for hiding this comment

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

SG


level = self.get_level(l)
if c.startswith("Args:"):
state = ("Args", level)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to check with our auto-doc generator and see it can parse the new style

Copy link
Contributor Author

Choose a reason for hiding this comment

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

在我们的文档里边其实规定了参数的风格:https://github.com/PaddlePaddle/Paddle/blob/develop/doc/fluid/dev/api_doc_std_cn.md。
而且现在绝大多数都是按照这种风格来的。

'W9003': ('All args with their types must be mentioned in doc string',
symbol + "-with-all-args",
'Used when not all arguments are in the doc string '),
'W9005': ('Missing docstring or docstring is too shorter',
Copy link
Contributor

Choose a reason for hiding this comment

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

shorter->short

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


#exit $TOTAL_ERRORS
#For now, just warning:
exit 0
Copy link
Contributor

Choose a reason for hiding this comment

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

It will be great that pylint only requires the author to polish the code style for the codes he/she has touched, instead of covering the whole file.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a great idea, but maybe we need consistency in the whole Python file? E.g., the old file is 2-space indentation, the rule could be 4-space indentation, we probably want the whole file to have the same 4-space indentation, rather than the modified lines. Some edge case is hard to handle as well, for example the developer changed the second line of a doc string, does the linter have to modify the first line as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks.

done

#exit $TOTAL_ERRORS
#For now, just warning:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we don't turn on it in CI, but fails locally? (user can still use git commit --no-verify to skip the check.

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

@helinwang helinwang Apr 12, 2018

Choose a reason for hiding this comment

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

我担心如果本地也不报失败,没有人会去花时间修复问题,理论上CI需要强制验证,不过可能我们可以有一个试运行期,本地报错,CI不强制认证。


#exit $TOTAL_ERRORS
#For now, just warning:
exit 0
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a great idea, but maybe we need consistency in the whole Python file? E.g., the old file is 2-space indentation, the rule could be 4-space indentation, we probably want the whole file to have the same 4-space indentation, rather than the modified lines. Some edge case is hard to handle as well, for example the developer changed the second line of a doc string, does the linter have to modify the first line as well?

@gongweibao gongweibao requested a review from luotao1 April 12, 2018 05:19
@panyx0718 panyx0718 requested a review from shanyi15 May 1, 2018 09:44
panyx0718
panyx0718 previously approved these changes May 1, 2018

return True

def all_args_in_doc(self, node, doc):
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's talk offline. I'm excited that you can get args from a python function. We can use this solution to detect API change and enforce API-compatibility.

@panyx0718
Copy link
Contributor

@shanyi15 can you talk with @gongweibao and see if the current python comment requirement can satisfy the API documentation on the website?

@shanyi15
Copy link
Collaborator

shanyi15 commented May 1, 2018

@panyx0718 Sure

@gongweibao gongweibao requested a review from wanglei828 May 4, 2018 05:13
@gongweibao gongweibao merged commit 9d723b8 into PaddlePaddle:develop May 28, 2018
@gongweibao gongweibao deleted the pylint branch June 11, 2018 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants