-
Notifications
You must be signed in to change notification settings - Fork 224
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
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`.
pygmt/helpers/utils.py
Outdated
>>> 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
""" | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the following code better?
kwargs.get(arg) is not None and kwargs.get(arg) is not False for arg in args | |
kwargs.get(arg) not in (None, False) for arg in args |
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 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_kwargs
function wherebyNone
values are allowed, when actually, we want to drop theNone
. Specifically, this would fix potential bugs inbasemap
,coast
andgrdgradient
.This
kwargs.get(arg)
idea is actually adapted from #731 (comment).Fixes #1665
Reminders
make format
andmake check
to 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