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
19 changes: 13 additions & 6 deletions pygmt/helpers/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,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 @@ -397,13 +397,20 @@ 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:
for short_param, long_alias in aliases.items():
if long_alias in kwargs and short_param in kwargs:
raise GMTInvalidInput(
f"Arguments in short-form ({arg}) and long-form ({alias}) can't coexist"
f"Parameters in short-form ({short_param}) and "
f"long-form ({long_alias}) can't coexist."
)
if alias in kwargs:
kwargs[arg] = kwargs.pop(alias)
if long_alias in kwargs:
kwargs[short_param] = kwargs.pop(long_alias)
elif short_param in kwargs:
msg = (
f"Short-form parameter ({short_param}) is not recommended. "
f"Use long-form parameter '{long_alias}' instead."
)
warnings.warn(msg, category=SyntaxWarning, stacklevel=2)
return module_func(*args, **kwargs)

new_module.aliases = aliases
Expand Down