Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make optional in docstrings optional #14862

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

Merged
merged 1 commit into from
Aug 12, 2019
Merged

Conversation

timhoffm
Copy link
Member

PR Summary

I think this has been discussed somewhere recently, but I don't remember where.

Numpydoc unconditionally states

If it is not necessary to specify a keyword argument, use optional:

Explicitly stating that a parameter is optional is usually not necessary, it's clear from the signature and/or documentation of a default value. Let's remove optional to reduce the clutter in docstrings.

The parantheses in (float, float) have already been there, but since this popped up in another discussion, it's reasonable to explicitly mention them here.

@tacaswell tacaswell added this to the v3.2.0 milestone Jul 22, 2019
@tacaswell
Copy link
Member

I don't think we have any yet, but we are going to eventually have required keyword arguments. Do we want to call those out as explicitly required?

I am 50/50 on this change. See the argument for reducing clutter, but it means you now have to look in two places instead of one to get all of the information you need.

@timhoffm
Copy link
Member Author

I‘d point out mandatory kwargs explicitly rather than optional ones.

There will be far less mandatory ones, and the „standard“ notion of Python kwargs is optional.

Another weak argument for removing optional is that type definitions in numpydoc have to be on a logical line. You run into conflicts more often between the 80 char limit and backslash continuation, which must be continued with 0-indent on the he following line.

@anntzer
Copy link
Contributor

anntzer commented Jul 22, 2019

I'm +1 on this change, especially for cases where the default is spelled out on the same line anyways (in which case it's clear it's optional...).

@timhoffm
Copy link
Member Author

For reference:

  • NumPy and SciPy both use name : type, optional. Defaults are only written in the body of the docstring.
  • Pandas uses name : type, default xxx.

@timhoffm
Copy link
Member Author

timhoffm commented Jul 24, 2019

Should we be a little more defensive and specific?

For keyword arguments use {name} : {type}, default: {val}, or if the default is not simple to describe use {name} : {type}, optional and describe the default in the text.

@anntzer
Copy link
Contributor

anntzer commented Jul 24, 2019

looks like a good start

@timhoffm
Copy link
Member Author

timhoffm commented Aug 8, 2019

Reworded according to #14862 (comment)

@timhoffm
Copy link
Member Author

@tacaswell does the revised version reduce your concern?

@timhoffm timhoffm force-pushed the doc-writing branch 3 times, most recently from 8e9193c to ada765b Compare August 11, 2019 10:20
Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

This seems reasonable to me.

@tacaswell tacaswell merged commit f4515eb into matplotlib:master Aug 12, 2019
@timhoffm timhoffm deleted the doc-writing branch August 12, 2019 21:04
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.

6 participants