NilsJPWerner / autoDocstring

VSCode extension that generates docstrings for python files
MIT License
676 stars 163 forks source link

Returns and Raises switched on Google docstring template #244

Open irenepc opened 2 years ago

irenepc commented 2 years ago

According to the style guide, Returns should be outlined prior to Raises in google style docstring, yet when I generate one that has both, the Raises appear before the returns https://google.github.io/styleguide/pyguide.html The same can be seen in this example .mustache in the repo https://github.com/NilsJPWerner/autoDocstring/blob/HEAD/src/docstring/templates/google.mustache

Thanks for a great extension!

irenepc commented 2 years ago

I think these changes to the .mustache fix the issue.

{{! Google Docstring Template }}
{{summaryPlaceholder}}

{{extendedSummaryPlaceholder}}
{{#parametersExist}}

Args:
{{#args}}
    {{var}} ({{typePlaceholder}}): {{descriptionPlaceholder}}
{{/args}}
{{#kwargs}}
    {{var}} ({{typePlaceholder}}, optional): {{descriptionPlaceholder}}. Defaults to {{&default}}.
{{/kwargs}}
{{/parametersExist}}
{{#returnsExist}}

Returns:
{{#returns}}
    {{typePlaceholder}}: {{descriptionPlaceholder}}
{{/returns}}
{{/returnsExist}}
{{#exceptionsExist}}

Raises:
{{#exceptions}}
    {{type}}: {{descriptionPlaceholder}}
{{/exceptions}}
{{/exceptionsExist}}
{{#yieldsExist}}

Yields:
{{#yields}}
    {{typePlaceholder}}: {{descriptionPlaceholder}}
{{/yields}}
{{/yieldsExist}}
DavidTWynn commented 1 year ago

Yes, I see the same thing. Using your template worked for me. One other thing is the style guide says a period after the summaryPlaceholder on line one. These are my first 2 lines:

{{! Google Docstring Template }}
{{summaryPlaceholder}}.

It looks like there are some other things missing from the Google style. Section 3.8 describes what to do for google python docstrings, and in 3.8.4 it says when documenting a class to use the 'Attributes:' marker for public attributes of the class. From a quick check of the template_data.ts, I did not see that attributes are being looked for.

Also, if it were to be added I see it doesn't detect the arguments/attributes currently for dataclasses or Pydantic.

Here is the google template without typing:

{{! Google Docstring Template without Types for Args, Returns or Yields }}
{{summaryPlaceholder}}.

{{extendedSummaryPlaceholder}}
{{#parametersExist}}

Args:
{{#args}}
    {{var}}: {{descriptionPlaceholder}}
{{/args}}
{{#kwargs}}
    {{var}}: {{descriptionPlaceholder}}. Defaults to {{&default}}.
{{/kwargs}}
{{/parametersExist}}
{{#returnsExist}}

Returns:
{{#returns}}
    {{descriptionPlaceholder}}
{{/returns}}
{{/returnsExist}}
{{#yieldsExist}}

Yields:
{{#yields}}
    {{descriptionPlaceholder}}
{{/yields}}
{{/yieldsExist}}
{{#exceptionsExist}}

Raises:
{{#exceptions}}
    {{type}}: {{descriptionPlaceholder}}
{{/exceptions}}
{{/exceptionsExist}}