Uh oh!
There was an error while loading. Please reload this page.
None shall not pass args_in_kwargs - #1815
Conversation
Fixes bug in `args_in_kwargs` function whereby `None` values are allowed, when actually, we want to drop the `None`.
Uh oh!
There was an error while loading. Please reload this page.
| >>> args_in_kwargs(args=["A", "B"], kwargs={"B": 0}) | ||
| True | ||
| """ | ||
| return any(arg in kwargs for arg in args) | ||
| return any(kwargs.get(arg) for arg in args) |
There was a problem hiding this comment.
Need to modify this one-liner return statement so that args_in_kwargs(args=["A", "B"], kwargs={"B": 0}) returns True.
There was a problem hiding this comment.
So, we should change it to:
return any(kwargs.get(arg) is not None for arg in args)
right?
There was a problem hiding this comment.
Close. I had to do return any(kwargs.get(arg) is not None and kwargs.get(arg) is not False for arg in args) so that arguments that are False don't count. Done in 7c3c6b4
Uh oh!
There was an error while loading. Please reload this page.
| """ | ||
| return any(arg in kwargs for arg in args) | ||
| return any( | ||
| kwargs.get(arg) is not None and kwargs.get(arg) is not False for arg in args |
There was a problem hiding this comment.
Is the following code better?
| kwargs.get(arg) isnotNoneandkwargs.get(arg) isnotFalseforarginargs | |
| kwargs.get(arg) notin (None, False)forarginargs |
There was a problem hiding this comment.
This doesn't work, need to use is instead of in or == to do the check against None or False:
323 >>> args_in_kwargs(args=["A", "B"], kwargs={"B": 0})
Expected:
True
Got:
False
This reverts commit a9831f3.
Fixes bug in `args_in_kwargs` function whereby `None` values are allowed, when actually, we want to drop the `None`. * Add failing test for when param=0 * Check that argument is not None or False
Description of proposed changes
Fixes bug in
args_in_kwargsfunction wherebyNonevalues are allowed, when actually, we want to drop theNone. Specifically, this would fix potential bugs inbasemap,coastandgrdgradient.This
kwargs.get(arg)idea is actually adapted from #731 (comment).Fixes#1665
Reminders
make formatandmake checkto make sure the code follows the style guide.doc/api/index.rst.Slash Commands
You can write slash commands (
/command) in the first line of a comment to performspecific operations. Supported slash commands are:
/format: automatically format and lint the code/test-gmt-dev: run full tests on the latest GMT development version