Skip to content

Commit

Permalink
Raise a warning for the use of short-form parameters when long-forms …
Browse files Browse the repository at this point in the history
…are available (GenericMappingTools#1316)
  • Loading branch information
seisman authored and Josh Sixsmith committed Dec 21, 2022
1 parent 9a62fa8 commit 337c59a
Showing 1 changed file with 13 additions and 6 deletions.
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

0 comments on commit 337c59a

Please sign in to comment.