-
Notifications
You must be signed in to change notification settings - Fork 225
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
Raise an exception if the given parameter is not recognized and is longer than 2 characters #1792
Conversation
…than 2 characters
pygmt/helpers/utils.py
Outdated
# raise an exception for unrecognized options | ||
for key in kwargs: | ||
if len(key) > 2: | ||
raise GMTInvalidInput(f"Unrecognized parameter '{key}'.") | ||
# Exclude arguments that are None and False |
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.
Perhaps we can rewrite the whole function like below, so we don't need to loop over kwargs
three times.
for key in filtered_kwargs:
if len(key) > 2: # raise an exception for unrecognized options
raise GMTInvalidInput(f"Unrecognized parameter '{key}'.")
if (kwargs[key] is None or kwargs[key] is False):
pass # Exclude arguments that are None and False
elif is_nonstr_iter(kwargs[key]):
for value in kwargs[key]:
gmt_args.append(f"-{key}{value}")
elif kwargs[key] is True:
gmt_args.append(f"-{key}")
else:
gmt_args.append(f"-{key}{kwargs[key]}")
return " ".join(sorted(gmt_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.
Yep, looks good. It might conflict with #1487 but we can fix it 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 had a last minute thought that the len(key) > 2
check should probably go in the @use_alias
decorator, but I really like this refactor so let's just go with this 😝
…nger than 2 characters (GenericMappingTools#1792)
Description of proposed changes
Address #256.
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