Skip to content

Commit ac28e72

Browse files
seismanweiji14
andauthored
Raise an error if short- and long-form arguments coexist (#537)
Raise an error if short- and long-form arguments coexist, i.e., don't allow arguments like `B="af", frame=True`. Co-authored-by: Wei Ji <[email protected]>
1 parent ef0099e commit ac28e72

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pygmt/helpers/decorators.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,13 @@ def use_alias(**aliases):
180180
R = bla J = meh
181181
>>> my_module(region='bla', projection='meh')
182182
R = bla J = meh
183-
183+
>>> my_module(
184+
... region='bla', projection='meh', J="bla"
185+
... ) # doctest: +NORMALIZE_WHITESPACE
186+
Traceback (most recent call last):
187+
...
188+
pygmt.exceptions.GMTInvalidInput:
189+
Arguments in short-form (J) and long-form (projection) can't coexist
184190
"""
185191

186192
def alias_decorator(module_func):
@@ -194,6 +200,10 @@ def new_module(*args, **kwargs):
194200
New module that parses and replaces the registered aliases.
195201
"""
196202
for arg, alias in aliases.items():
203+
if alias in kwargs and arg in kwargs:
204+
raise GMTInvalidInput(
205+
f"Arguments in short-form ({arg}) and long-form ({alias}) can't coexist"
206+
)
197207
if alias in kwargs:
198208
kwargs[arg] = kwargs.pop(alias)
199209
return module_func(*args, **kwargs)

0 commit comments

Comments
 (0)