From 2938c2ab70bcd9a32bfe2b5516776ae67511dcc7 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 2 Jun 2021 14:59:43 -0400 Subject: [PATCH 1/3] Raise an warning for the use of short-form parameters when long-forms are available --- pygmt/helpers/decorators.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pygmt/helpers/decorators.py b/pygmt/helpers/decorators.py index 729234a4d66..4b27904b813 100644 --- a/pygmt/helpers/decorators.py +++ b/pygmt/helpers/decorators.py @@ -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): @@ -375,10 +375,16 @@ def new_module(*args, **kwargs): 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" + 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) return module_func(*args, **kwargs) new_module.aliases = aliases From 23e9dd67a999cb0c984dea13fb993434f4593944 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 9 Jun 2021 23:07:36 -0400 Subject: [PATCH 2/3] Raise SyntaxWarning instead --- pygmt/helpers/decorators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/helpers/decorators.py b/pygmt/helpers/decorators.py index 4b27904b813..9bc125bde75 100644 --- a/pygmt/helpers/decorators.py +++ b/pygmt/helpers/decorators.py @@ -384,7 +384,7 @@ def new_module(*args, **kwargs): f"Short-form parameter ({arg}) is not recommended. " f"Use long-form parameter '{alias}' instead." ) - warnings.warn(msg, category=FutureWarning, stacklevel=2) + warnings.warn(msg, category=SyntaxWarning, stacklevel=2) return module_func(*args, **kwargs) new_module.aliases = aliases From 30cf3e2cd2f7e33ad2fbc37cf081fdc02442899a Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Tue, 15 Jun 2021 16:33:53 -0400 Subject: [PATCH 3/3] Rename variables to make the codes more readable --- pygmt/helpers/decorators.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pygmt/helpers/decorators.py b/pygmt/helpers/decorators.py index 9bc125bde75..791356f601d 100644 --- a/pygmt/helpers/decorators.py +++ b/pygmt/helpers/decorators.py @@ -372,17 +372,18 @@ 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"Parameters 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) - elif arg in kwargs: + if long_alias in kwargs: + kwargs[short_param] = kwargs.pop(long_alias) + elif short_param in kwargs: msg = ( - f"Short-form parameter ({arg}) is not recommended. " - f"Use long-form parameter '{alias}' instead." + 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)