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

Fixed #27656 -- Updated docstring verbs according to PEP 257. #7763

Merged
merged 1 commit into from
Mar 4, 2017

Conversation

desecho
Copy link
Contributor

@desecho desecho commented Dec 29, 2016

and passes to the handler, returning the result of the handler.
Assumes defaults for the query environment, which can be overridden
The master request method. Compose the environment dictionary
and pass to the handler, return the result of the handler.
Copy link
Member

Choose a reason for hiding this comment

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

, -> , and

@@ -674,9 +674,9 @@ def _login(self, user, backend=None):

def logout(self):
"""
Removes the authenticated user's cookies and session object.
Remove the authenticated user's cookies and session object.
Copy link
Member

Choose a reason for hiding this comment

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

"Log out the user by removing the cookies and session object."
(remove second sentence)

@@ -701,7 +701,7 @@ def _parse_json(self, response, **extra):
return response._json

def _handle_redirects(self, response, **extra):
"Follows any redirects by requesting responses from the server using GET."
"Follow any redirects by requesting responses from the server using GET."
Copy link
Member

Choose a reason for hiding this comment

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

Pep257 says, "Triple quotes are used even though the string fits on one line. This makes it easy to later expand it."

@@ -441,14 +441,14 @@ def __init__(self, enforce_csrf_checks=False, **defaults):

def store_exc_info(self, **kwargs):
"""
Stores exceptions when they are generated by a view.
Store exceptions when they are generated by a view.
"""
self.exc_info = sys.exc_info()

@property
def session(self):
"""
Copy link
Member

Choose a reason for hiding this comment

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

Should these by one liners ? e.g. """Obtain the current session variables.""" -- we currently don't have consistency about that.

@desecho
Copy link
Contributor Author

desecho commented Dec 29, 2016

@timgraham I'll be making the changes you suggested as well as fixes for the verb style. Also, I noticed that this coding style is not being followed as well. I should probably be fixing that as well - I go through the all of the comments anyway.

In test docstrings, state the expected behavior that each test demonstrates. Don’t include preambles such as “Tests that” or “Ensures that”.

And I assume it is a good idea to also make sure these PEP rules are being followed as well:

  • Triple quotes are used even though the string fits on one line. This makes it easy to later expand it.
  • The closing quotes are on the same line as the opening quotes. This looks better for one-liners.
  • There's no blank line either before or after the docstring. (except for classes)
  • The docstring is a phrase ending in a period.

@timgraham
Copy link
Member

Keep this patch focused on django/ only -- don't worry about test docstrings, there's a separate ticket for that.
The PEP rules you mentioned are fine.

@desecho
Copy link
Contributor Author

desecho commented Dec 29, 2016

Ok. Also I noticed that the wrapping is sometimes different. It can be 72 or less than 79. Since you mentioned it in the commit we should probably make it consistent to 79.

Documentation, comments, and docstrings should be wrapped at 79 characters, even though PEP 8 suggests 72.

@timgraham
Copy link
Member

If you're making significant changes to the docstring, feel free to adjust the length to 79, otherwise don't make needless changes.

@desecho desecho force-pushed the ticket_27656 branch 2 times, most recently from 247e63a to 35785e9 Compare December 29, 2016 17:45
@desecho
Copy link
Contributor Author

desecho commented Dec 29, 2016

I made some changes. Please see if I am on the right track.

@desecho desecho force-pushed the ticket_27656 branch 4 times, most recently from 0be176f to c6dbc53 Compare December 29, 2016 18:21
@@ -158,7 +158,7 @@ class SongAdmin(admin.ModelAdmin):

def test_custom_modelforms_with_fields_fieldsets(self):
"""
# Regression test for #8027: custom ModelForms with fields/fieldsets
Copy link
Member

Choose a reason for hiding this comment

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

As I mentioned before, please don't modify any test docstrings for this PR.

The test client has been asked to follow a redirect loop.
"""
"""The test client has been asked to follow a redirect loop."""

Copy link
Member

Choose a reason for hiding this comment

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

I'd skip the blank line after the class docstring changes. Focus on changing the verbs only.

# reporting purposes. Needed to maintain backwards
# compatibility with existing admin templates.
"""
Wrapper class used to return items in a list_editable
Copy link
Member

Choose a reason for hiding this comment

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

Might as well reflow the line length in a case like this.

@@ -420,8 +419,8 @@ def _check_prepopulated_fields_value(self, obj, model, val, label):
]))

def _check_prepopulated_fields_value_item(self, obj, model, field_name, label):
""" For `prepopulated_fields` equal to {"slug": ("title",)},
`field_name` is "title". """
"""For `prepopulated_fields` equal to {"slug": ("title",)},
Copy link
Member

Choose a reason for hiding this comment

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

Be consistent about the multiline style -- use

"""
....
"""

# perform imports because of the risk of import loops. It mustn't
# call get_app_config().
"""
Since this method is called when models are imported, it cannot
Copy link
Member

Choose a reason for hiding this comment

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

This content isn't a docstring, so inline comment is more appropriate.

"""
Class representing a Django application and its configuration.
"""
"""Class representing a Django application and its configuration."""
Copy link
Member

Choose a reason for hiding this comment

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

If there aren't any content changes required, don't bother changing a docstring like this.

@timgraham
Copy link
Member

Please do only verb changes in this PR. I think all other changes could be refactored automatically with some tool if we decide to do that. Otherwise, this is just creating a huge unreviewable patch.

@desecho
Copy link
Contributor Author

desecho commented Dec 30, 2016

So I assume this means don't follow your previous suggestions and do only verb changes. I caught few typos - I will include them as well.

@timgraham
Copy link
Member

Yes, sorry I had second thoughts about this when I started seeing how many more changes would be required as well as the thought that other changes could be automated.

@timgraham
Copy link
Member

On further thought, I'd hold off on doing further changes for a couple weeks so that you don't create merge conflicts with all that code that will be removed in Django 2.0 as part of the ending deprecations (#7773). I'll leave a note when it's a good time to continue. Thanks!

@desecho desecho force-pushed the ticket_27656 branch 2 times, most recently from 197a583 to e68078c Compare January 5, 2017 19:49
@desecho desecho changed the title Fixed #27656 -- Fix comment verb style according to PEP 257. [WIP] Fixed #27656 -- Fix comment verb style according to PEP 257. Jan 6, 2017
@desecho
Copy link
Contributor Author

desecho commented Jan 21, 2017

I guess we can continue with this ticket since #7773 got merged.

@timgraham
Copy link
Member

Sure, feel free to rebase. Maybe you can submit some smaller commits for easier review, such as only doing "django.contrib" so that the patch doesn't get so long that GitHub starts displaying "Load diff" buttons. It gets tedious to click those to review things.

@desecho desecho changed the title [WIP] Fixed #27656 -- Fix comment verb style according to PEP 257. Fixed #27656 -- Fix comment verb style according to PEP 257. Jan 25, 2017
@desecho
Copy link
Contributor Author

desecho commented Jan 25, 2017

I completed all of the changes.

@timgraham
Copy link
Member

What was your methodology for identifying places that need to be fixed? Working my way through contrib.admin (so don't bother reviewing that one) I see a lot of places where, for example, the first verb in the sentence was fixed but not the second (e.g. "Remove the authenticated user's ID from the request and flushes their". Even grepping for "Returns" shows places that weren't updated. Another phrasing to check for is something like "If no user is retrieved an instance of AnonymousUser is returned." which should be "If no user is retrieved, return an instance of AnonymousUser." I know this is really tedious, but reviewing a partially completed attempt at this isn't fun either.

@timgraham
Copy link
Member

django.contrib commit merged in 5411821 (with many edits).

@timgraham timgraham changed the title Fixed #27656 -- Fix comment verb style according to PEP 257. Fixed #27656 -- Updated docstring verbs according to PEP 257. Mar 4, 2017
@timgraham timgraham merged commit 86de930 into django:master Mar 4, 2017
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.

2 participants