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

bpo-30181: parse docstring using pydoc #1505

Conversation

brianmay
Copy link

@brianmay brianmay commented May 9, 2017

Rebased and copied Ben Finney's changes from http://bugs.python.org/issue30181

I hope master is the correct branch to merge this into.

https://bugs.python.org/issue30181

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA. This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

Thanks again to your contribution and we look forward to looking at it!

@brianmay brianmay changed the title Wip/issue/issue30181 parse docstring using pydoc bpo-30181 parse docstring using pydoc May 9, 2017
@brianmay brianmay changed the title bpo-30181 parse docstring using pydoc bpo-30181: parse docstring using pydoc May 9, 2017
@brianmay
Copy link
Author

brianmay commented May 9, 2017

Apparently trivial changes don't require a CLA. Does this count as a trivial change? In any case, the changes are from Ben Finney, not myself, so I suspect it isn't going to help if I sign the CLA.

@brianmay
Copy link
Author

brianmay commented May 9, 2017

The two tests that fail don't appear to be valid PEP 257 docstring to me. So I think maybe the tests need to be modified.

"""
Return the test case short description from a docstring.

Ths docstring is parsed by the standard `pydoc.splitdoc` function
Copy link
Member

Choose a reason for hiding this comment

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

This is an implementation detail. Both short_description_from_docstring and pydoc.splitdoc are not public API, therefore the docstring is interested only for readers of these sources. It can be just a comment. But there is no much sense to just repeat the code by words in a docstring or comment.

Copy link
Author

Choose a reason for hiding this comment

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

There appears to be different ideas at play here surrounding the use docstrings. With one view being docstrings should only document the public API, so users of the API know how to use the package. The other view being docstrings are equally applicable for internal functions, which should have a well defined API for internal use, so internal programmers can tell what the function does without peering into the source. Any external references to help justify one or the other side of this argument appreciated (I have no opinions on this yet myself).

Copy link
Author

@brianmay brianmay May 10, 2017

Choose a reason for hiding this comment

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

I have also had the out of band comment from Ben saying just because it isn't a public API doesn't make the docstring any less useful. Since a docstring will be available to anyone introspecting the object whether private or public

Copy link
Member

Choose a reason for hiding this comment

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

Docstrings of internal functions are not forbidden, they are just not necessary. Comments would be enough (see PEP 8).

In any case neither comment, nor docstring shouldn't just repeat the code. They should describe what function does, but not how it does this. Otherwise any change of the code will make a docstring or a comment incorrect.

Note also that the function name itself serves the documenting function.

Copy link
Author

Choose a reason for hiding this comment

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

How about:

def short_description_from_docstring(text):
    # Return the summary line from a docstring.
    # If there is no summary line, return None.
    ...

The use of the word "summary line" comes straight from PEP-257.

@unittest.skipIf(
sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def testShortDescriptionWithSurroundingSpaceOneLineDocstring(self):
Copy link
Member

Choose a reason for hiding this comment

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

I think it is enough to just add spaces or newlines in the two preceding tests.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, not sure I understand. You appear to be saying that we should use the same docstring as for the testShortDescriptionWithOneLineDocstring test but with extra white space. However it is a different test - doesn't that mean it needs a different doc string to describe how it is different from the previous docstring?

Copy link
Member

Choose a reason for hiding this comment

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

I mean that adding spaces at the start and end of the docstring of testShortDescriptionWithOneLineDocstring and adding a newline and indentation at the start of the docstring of testShortDescriptionWithMultiLineDocstring will cover cases tested by new testes. No new tests will be needed.

Copy link
Author

Choose a reason for hiding this comment

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

Oh, OK, I think I understand now. So to clarify, you feel there is no need to have a separate test for the no-leading/trailing whitespace case?

@brettcannon
Copy link
Member

FYI Ben Finney has signed the CLA, although this is not a trivial change if you make any changes to the PR yourself, @brianmay then we will need you to sign the CLA, so please do so.

"""
Return the test case short description from a docstring.

Ths docstring is parsed by the standard `pydoc.splitdoc` function
Copy link
Member

Choose a reason for hiding this comment

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

Docstrings of internal functions are not forbidden, they are just not necessary. Comments would be enough (see PEP 8).

In any case neither comment, nor docstring shouldn't just repeat the code. They should describe what function does, but not how it does this. Otherwise any change of the code will make a docstring or a comment incorrect.

Note also that the function name itself serves the documenting function.

doc = self._testMethodDoc
return doc and doc.split("\n")[0].strip() or None

""" Return a one-line description of the test, if any; otherwise None. """
Copy link
Member

Choose a reason for hiding this comment

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

shortDescription() is a public API. Your change removes useful information from its docstring.

Copy link
Author

@brianmay brianmay May 11, 2017

Choose a reason for hiding this comment

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

Not sure that the previous description is entirely relevant. Also does saying "The default implementation" add any useful information? How about:

def shortDescription(self):
    """Returns a one-line description of the test, or None if no
    description has been provided.

    This method returns the summary line of
    the specified test method's docstring, as per PEP-257.
    """
    ...

@unittest.skipIf(
sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def testShortDescriptionWithSurroundingSpaceOneLineDocstring(self):
Copy link
Member

Choose a reason for hiding this comment

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

I mean that adding spaces at the start and end of the docstring of testShortDescriptionWithOneLineDocstring and adding a newline and indentation at the start of the docstring of testShortDescriptionWithMultiLineDocstring will cover cases tested by new testes. No new tests will be needed.

@brianmay
Copy link
Author

I have signed the CLA - is it possible to remove "CLA not signed" tag?

@brettcannon
Copy link
Member

Ah, I see the issue. Your PR has code from https://github.com/benf-wspdigital who has not signed the CLA, so the bot is blocking it as the provenance of the code isn't CLA-clean. Any way of getting that git user to sign the CLA?

@brianmay
Copy link
Author

I am confused; that looks like Ben Finney's account, and you previously said he had signed the CLA.

@encukou
Copy link
Member

encukou commented May 11, 2017

The bot doesn't recognize him because he has not added his Github username to his profile at bugs.python.org.

@brettcannon
Copy link
Member

@encukou is right. Ben Finney has signed based on his bugs.python.org account, but the bot nor I can verify that benf-swpdigital on GitHub is Ben Finney.

@brianmay
Copy link
Author

@encukou
Copy link
Member

encukou commented May 12, 2017

Ben Finney has signed based on his bugs.python.org account, but the bot nor I can verify that benf-swpdigital on GitHub is Ben Finney.

GitHub determines attribution by the e-mail in the commit. This is just text, and easily spoofable – notice how the commits here ended up attributed to Ben without any action on his part, and without GitHub's knowledge of what's on b.p.o.
So, you can tell benf-swpdigital on GitHub registered with the e-mail address in these commits.

Anyway, instead you probably want to verify the patches here are the ones from Ben, i.e. compare them to the ones on b.p.o.

@brettcannon
Copy link
Member

Just an FYI, this whole CLA issue of people being nice and opening PRs on other people's behalf is being discussed at python/devguide#195 .

@terryjreedy
Copy link
Member

There would have been less confusion about who has not signed the CLA if the Knight's explanatory message began with "Hello :".

@brettcannon
Copy link
Member

@@ -338,6 +339,25 @@ def __exit__(self, exc_type, exc_value, tb):
.format(logging.getLevelName(self.level), self.logger.name))


def short_description_from_docstring(text):
Copy link
Member

Choose a reason for hiding this comment

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

This function name should start with an underscore since it's not meant to be part of the public API. Also, I think a shorter name should be used like _make_short_description(docstring) or _get_short_description(docstring). Information about the arguments can be gotten from the argument names or function docstring.

@brettcannon
Copy link
Member

I talked with our lawyer and he said that as long as Ben and Brian have both signed the CLA then we are fine. So @brianmay can you just tell us your bugs.python.org username and I can manually check you also signed and then this PR will be cleared from a CLA perspective.

@brianmay
Copy link
Author

@Mariatta said above "I checked that @brianmay has signed the CLA in b.p.o. His b.p.o username is brian".

I don't think there is any need for me to sign the CLA again after it has already been confirmed that I have signed it.

@vstinner
Copy link
Member

@Mariatta said above "I checked that @brianmay has signed the CLA in b.p.o. His b.p.o username is brian". I don't think there is any need for me to sign the CLA again after it has already been confirmed that I have signed it.

I see that http://bugs.python.org/user14312 has "Contributor Form Received | Yes", bpo login "brian", GitHub login "brianmay".

But I just removed the "CLA not signed" label, and the bot ... added it again, as you didn't sign it :-(

I only see one bpo user with github login="brianmay".

Could it be a mismatch based on the mail address?

@brettcannon: Would you mind to take a look please?

@Mariatta
Copy link
Member

@Haypo This PR is kinda unique.. What happened is that @brianmay made the PR based on Ben Finney's patch. Because of this the bot tries to check if both Ben and Brian have signed the CLA.
In https://bugs.python.org/msg293522, Ben Finney stated that he does not want to create GitHub account. Since he does not have GitHub account, the bot can't check whether he signed the CLA or not.

I see that both Ben and Brian have signed the CLA. I think from CLA perspective it's clear.
But wouldn't hurt if both you and/or @brettcannon take another look and confirm that both users have signed the CLA.

Otherwise, If the conflict can be resolved, and if you approve this PR, I think this is good to go.

@vstinner
Copy link
Member

I suggest to export the change as a patch (git diff master.. > patch), create a new PR (git checkout -b pydoc; git apply patch; git commit -a), and credit Ben Finney in the commit message, like:

Co-Authored-By: Ben Finney <xxx@xxx>

@cjerdonek
Copy link
Member

On the PR itself, note that I have review comments from a couple months ago that haven't been addressed.

@brettcannon
Copy link
Member

Both Ben and Brian have signed the CLA and it's just Ben's refusal to set up a GitHub account with his bugs.python.org account that's causing the CLA bot to say this PR isn't in the clear. So as long as there are no other commits from anyone but Ben and Brian (which is what is currently true), then from a CLA perspective we're in the clear in this case.

@cjerdonek can you change your review to "request changes" if you think they should be addressed before this PR is considered for acceptance? Plus there are merge conflicts that have to be fixed.

Copy link
Member

@cjerdonek cjerdonek left a comment

Choose a reason for hiding this comment

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

For backwards compatibility reasons, the PR should preserve the behavior that docstrings of the form 'abc\ndef' return the first line. It should also add a test for this case. While the PR can help ensure that PEP-257 compliant docstrings result in a useful result, it shouldn't require docstrings to be compliant to do so. (Many test-case docstrings out in the wild aren't.)

My suggestion would be to change the implementation of _get_short_description() to match the current implementation, with a call to strip() beforehand. The docstring of _get_short_description() should also be updated accordingly.

@brettcannon
Copy link
Member

To try and help move older pull requests forward, we are going through and backfilling 'awaiting' labels on pull requests that are lacking the label. Based on the current reviews, the best we can tell in an automated fashion is that a core developer requested changes to be made to this pull request.

If/when the requested changes have been made, please leave a comment that says, I have made the requested changes; please review again. That will trigger a bot to flag this pull request as ready for a follow-up review.

@cjerdonek
Copy link
Member

I'm closing this as it was separately resolved by PR #18175 for https://bugs.python.org/issue39450

@cjerdonek cjerdonek closed this Oct 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.