-
-
Notifications
You must be signed in to change notification settings - Fork 161
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
Add validation for optional parameters #431
Open
MatthewFlamm
wants to merge
10
commits into
numpy:main
Choose a base branch
from
MatthewFlamm:validate-optional-params
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4a89d03
validate optional parameters
MatthewFlamm cf34a10
consistent naming
MatthewFlamm 4cd733c
fix incompatible return
MatthewFlamm 9bcba56
Merge branch 'validate-optional-params' of github.com:MatthewFlamm/nu…
MatthewFlamm 83c4830
add inverse check and fix repeated check
MatthewFlamm 3ac46bf
dont use builtin type
MatthewFlamm 8cd766a
expand tests for None default
MatthewFlamm af10af7
add tests that distinguish between kwarg and default
MatthewFlamm 5daf396
Merge branch 'main' into validate-optional-params
MatthewFlamm 67b9eab
Fix whitespace from conflict merge
MatthewFlamm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is too strict of an interpretation of "optional".
For example, it is quite common to use
mykwarg=None
to indicate some form of default behavior, in which case I think it's safe to callmykwarg
"optional". In this case however, just becausea
is a keyword argument does not necessarily mean that it's optional. For example, ifa=None
would raise an exception (e.g. as might be expected in thehead1
function above) then I don't think it's necessarily correct to call thea
kwarg "optional".In other words, I think there needs to be a little more discussion in determining what "optional" really means in the context of the docstring standard, and if there's a distinction between optional/non-optional kwargs. I suspect that some projects do make such a distinction in their documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation would treat
mykwarg=None
as an optional parameter too. I can add a test here to ensure this.These meet the definition of optional in that users can opt to not provide it. There is no guarantee that this is a suitable choice when it is optional. In my opinion, if the function raises an error based on a default value, then this should be documented, probably in the
Raises
section.I welcome a discussion on this, should it be here or in a separate issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is also important that projects can turn off this check if they have specific requirements where a parameter is optional in its signature but not optional in implementation. It should be more common to have have the signature match the implementation requirement.