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

Inconsistent indication of types in docstrings #75

Closed
alvorithm opened this issue Mar 19, 2020 · 10 comments · Fixed by #148
Closed

Inconsistent indication of types in docstrings #75

alvorithm opened this issue Mar 19, 2020 · 10 comments · Fixed by #148
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@alvorithm
Copy link
Contributor

Problem

We have a variety of styles, including

  • Pyro-style (warranted where looking forward to near-term integration in Pyro)
  • name: type, explanation (for example - inputs: torch.tensor(), parameters theta)
  • name (type): explanation (for example - num_samples (int): desired number of samples). This is what PyTorch uses
  • variants of the above using braces { } or square brackets [ ] for the type

Suggested solution

Adopt the PyTorch convention across the board or elimitate types completely given that we're going to specify them in the signature already. This is what thinc does - loss.py example, and would be @Meteore 's favorite.

Action

  1. @jan-matthis @janfb @michaeldeistler: argue & vote in the comments.
  2. once decided, adjust if necessary the plugin that is generating the stubs for you.

FYI I get PyTorch-style docstring templates from VSCode's plugin autoDocstring by Nils Werner (0.4.0).

@alvorithm alvorithm added the documentation Improvements or additions to documentation label Mar 19, 2020
@michaeldeistler
Copy link
Contributor

I'm fine with pyTorch style

@jan-matthis
Copy link
Contributor

Pyro style docstrings in the slice sampler are on purpose, makes it's easier to potentially contribute the slice sampling kernel (so this should be a warranted inconsistency).

For the rest of the code base, I also think it's easiest to just use type annotations in the signature and avoid duplication in the docstring, so just use name: explanation.

@alvorithm
Copy link
Contributor Author

OK, then if Jan agrees we keep this issue open and reference it from a sanitize-docstrings PR (to be created).

This was referenced Mar 21, 2020
@alvorithm alvorithm added this to the DELFI feature parity milestone Apr 6, 2020
@jan-matthis
Copy link
Contributor

Here is a template for VSCode's autoDocstring without types:

{{! Google Docstring Template without types }}
{{summaryPlaceholder}}

{{extendedSummaryPlaceholder}}

{{#parametersExist}}
Args:
{{#args}}
    {{var}}: {{descriptionPlaceholder}}
{{/args}}
{{#kwargs}}
    {{var}}: {{descriptionPlaceholder}}
{{/kwargs}}
{{/parametersExist}}

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

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

@alvorithm
Copy link
Contributor Author

Thank you so much. This has to go in a file AFAICT, do you know what the canonical places/names/extensions would if project local or if global? Which one did you end up choosing?

@jan-matthis
Copy link
Contributor

I also wondered where to put the file, ended up placing it in a autodocstring subfolder relative to my global settings.json

@alvorithm
Copy link
Contributor Author

alvorithm commented Apr 7, 2020

I wonder whether with 3 of 4 (currently active) devs using vscode and a mandated format for the docstring it'd be too much of a stretch to version in git .vscode/settings.json and the template. Non-vscode users would not be affected, but could also get documentation (e.g. line length) for their own IDEs by looking at it. What do you think?

@alvorithm
Copy link
Contributor Author

I put it in ~/.config/Code - Insiders/User/autodocstring.template

@jan-matthis jan-matthis mentioned this issue Apr 16, 2020
6 tasks
@janfb
Copy link
Contributor

janfb commented Apr 16, 2020

Thanks! and where and how do you refer to autodocstring.template in vscode?

@jan-matthis
Copy link
Contributor

jan-matthis commented Apr 16, 2020

Thanks! and where and how do you refer to autodocstring.template in vscode?

I'll answer in #128

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants