Skip to content

Raise an error if short- and long-form arguments coexist #537

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

Merged
merged 4 commits into from
Jul 21, 2020
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
12 changes: 11 additions & 1 deletion pygmt/helpers/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,13 @@ def use_alias(**aliases):
R = bla J = meh
>>> my_module(region='bla', projection='meh')
R = bla J = meh

>>> my_module(
... region='bla', projection='meh', J="bla"
... ) # doctest: +NORMALIZE_WHITESPACE
Traceback (most recent call last):
...
pygmt.exceptions.GMTInvalidInput:
Arguments in short-form (J) and long-form (projection) can't coexist
"""

def alias_decorator(module_func):
Expand All @@ -194,6 +200,10 @@ def new_module(*args, **kwargs):
New module that parses and replaces the registered aliases.
"""
for arg, alias in aliases.items():
if alias in kwargs and arg in kwargs:
raise GMTInvalidInput(
f"Arguments in short-form ({arg}) and long-form ({alias}) can't coexist"
)
if alias in kwargs:
kwargs[arg] = kwargs.pop(alias)
return module_func(*args, **kwargs)
Expand Down