Skip to content
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 a warning for the use of short-form parameters when long-forms are available #1316

Merged
merged 7 commits into from
Jun 17, 2021
10 changes: 8 additions & 2 deletions pygmt/helpers/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def use_alias(**aliases):
Traceback (most recent call last):
...
pygmt.exceptions.GMTInvalidInput:
Arguments in short-form (J) and long-form (projection) can't coexist
Parameters in short-form (J) and long-form (projection) can't coexist.
"""

def alias_decorator(module_func):
Expand All @@ -375,10 +375,16 @@ def new_module(*args, **kwargs):
for arg, alias in aliases.items():
seisman marked this conversation as resolved.
Show resolved Hide resolved
if alias in kwargs and arg in kwargs:
raise GMTInvalidInput(
f"Arguments in short-form ({arg}) and long-form ({alias}) can't coexist"
f"Parameters in short-form ({arg}) and long-form ({alias}) can't coexist."
)
if alias in kwargs:
kwargs[arg] = kwargs.pop(alias)
elif arg in kwargs:
msg = (
f"Short-form parameter ({arg}) is not recommended. "
f"Use long-form parameter '{alias}' instead."
)
warnings.warn(msg, category=FutureWarning, stacklevel=2)
weiji14 marked this conversation as resolved.
Show resolved Hide resolved
return module_func(*args, **kwargs)

new_module.aliases = aliases
Expand Down