Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion pygmt/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,5 +306,23 @@ def args_in_kwargs(args, kwargs):
--------
bool
If one of the required arguments is in ``kwargs``.

Examples
--------

>>> args_in_kwargs(args=["A", "B"], kwargs={"C": "xyz"})
False
>>> args_in_kwargs(args=["A", "B"], kwargs={"B": "af"})
True
>>> args_in_kwargs(args=["A", "B"], kwargs={"B": None})
False
>>> args_in_kwargs(args=["A", "B"], kwargs={"B": True})
True
>>> args_in_kwargs(args=["A", "B"], kwargs={"B": False})
False
>>> args_in_kwargs(args=["A", "B"], kwargs={"B": 0})
True
"""
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
Copy link
Member

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?

Suggested change
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

Copy link
Member Author

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

)