Skip to content

Fixes docstrings and sets private members - #96

Closed
kushagra189 wants to merge 3 commits into
devfrom
bugfix/check_google_docstrings
Closed

kushagra189 wants to merge 3 commits into
devfrom
bugfix/check_google_docstrings

Conversation

@kushagra189

Copy link
Copy Markdown
Contributor

Description

Google type docstrings were improper and did not adhere to the required format. Fixed them as per the standards mentioned under the official guidelines. For reference check:

Fixes #70

Type of change

Please delete options that are not relevant.

  • Documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have not reduced the existing code coverage

@uniqueg uniqueg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm really sorry, but I think there's been quite some misunderstanding. Most of the changes you made are going in the wrong direction. The main point of the issue was to check the API docs on Read the Docs, find instances where the docstrings don't render well and try to fix those. In most cases this would probably mean to use the correct reStructuredText formatting, especially with a view to their use in Python docs (see here: https://www.python.org/dev/peps/pep-0287/#docstring-significant-features). A minor point was to check the consistency of the docstrings with the general recommendations (https://www.python.org/dev/peps/pep-0257/) and Google style (https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html), but in cases of ambiguity or multiple choices (see individual comments on class level vs class constructor docstrings, skipping explicit type annotations and defaults) keep the one that is most prevalent in our docs (because I did already think quite hard about which one to pick and might just not have caught every single instance for each when doing reviews).

I know this is annoying work, and in this particular case it will probably mean to go back and start a new PR entirely, so I understand if you'd rather not do it. Please let me know. And again, I'm really sorry for the misunderstanding, I should have caught earlier that this wasn't really going in the right direction (or perhaps the right direction, but way ahead).


Returns:
A Connexion app instance.
app (App): A Connexion app instance.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm really sorry to nag again about this PR (and probably should have seen this before), but since we are doing type hints (and those translate nicely to the API docs currently), we should not explicitly annotate parameter and return types in the docstrings again. The reason (apart from additional work) is that this is almost certainly going to lead to diverging actual type annotations and those mentioned in the docstrings, because comments are frequently not updated when the code is. The actual code base (and Python type hints can be considered part of that) should be the authoritative truth whenever possible, to avoid just the problem of code and comments diverging. Using only type hints is therefore MUCH better in this case. You can compare the second example here to see that this is fully within the Google docstring scope.

OSError: File cannot be read from or written to.
yaml.YAMLError: YAML cannot be (de)serialized.

Returns:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The Google style docstring examples or description here and here do not mention that sections like Raises and Returns should be arranged alphabetically. Rather, the order typically seems to be:

  • Summary line (should fit on one line)
  • Extended description
  • Notes
  • Args (followed by Attributes, if applicable)
  • Returns
  • Raises
  • Examples

specs: List[SpecConfig],
) -> App:
"""
Register OpenAPI specs with Connexion app.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Given that Connexion is also a package name, one could perhaps use connexion in single backticks as is described here for any Python identifiers (see third bullet point).

yaml.YAMLError: YAML cannot be (de)serialized.

Returns:
App: A Connexion app instance.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Again: please no type annotations in docstrings


Args:
config_file (Optional[str], optional): Path to config file in YAML
format. Defaults to None.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Defaults are also obvious from the function definitions and thus should be omitted. Diverging comments and code base are an even bigger problem here, as defaults are changed relatively frequently and users might end up assuming (and reporting) wrong usage parameters

contains the database object; `config['database']['collections']`
contains a dictionary of collection objects.
MongoConfig: Flask application with updated config:
``config['database']['database']`` contains the database object;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good!


Optionally, basic authorization can be set by environment variables.
Note:
Optionally, basic authorization can be set by environment variables.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps not really part of this issue, but how? :)

Comment thread foca/errors/exceptions.py
* `regular`: The exception is logged with the entire traceback
stack, usually on multiple lines.
exc (BaseException): The exception to log.
format (str, optional): One of 'oneline' (default), 'minimal', or

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All literals probably should have double backticks surrounding them

Comment thread foca/foca.py
YAML file structure, see :py:class:`foca.models.config.Config()`.
config (Optional[str], optional): Path to a YAML application
configuration file. For required YAML file structure, see
:py:class:`foca.models.config.Config()`. Defaults to None.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does the use of the : to define the Python identifier type (according to this document, fourth bullet point) lead to improved rendering? Specifically, does it create a link to that model? If not, I think we can omit it. Otherwise I think we should use wherever we are referring to a Python identifier

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It actually seems to do so with the type definition, but not sure it will also do it without. I'm wondering because the behavior is mixed: some (perhaps all?) references to FOCA modules/classes are linked on the API docs, but if, in a description of a parameter of a function or method, we are referring to another parameter in that same method, there is no link created. Ideally, of course, all such instances should be cross-linked, with the exception perhaps of members in external Python modules (guess that would be too much to ask from Read the Docs, although I think VS Code with the Python extension indeed does that)

Comment thread foca/security/auth.py
Raises:
connexion.exceptions.Unauthorized: Raised if JWT could not be
successfully validated.
Unauthorized: Raised if JWT could not be successfully validated.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unauthorized is not a standard Python error, and I think it's important that we indicate what error is raised specifically.

@kushagra189

Copy link
Copy Markdown
Contributor Author

Deleting this PR and the branch since the changes were not in line with the required flow.

@kushagra189
kushagra189 deleted the bugfix/check_google_docstrings branch March 15, 2021 04:30
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.

Fix docstring formatting & set private members

2 participants