1212from inspect import Parameter , signature
1313
1414import numpy as np
15- from pygmt .exceptions import GMTInvalidInput , GMTValueError
15+ from pygmt .exceptions import GMTInvalidInput , GMTParameterError , GMTValueError
1616from pygmt .helpers .utils import is_nonstr_iter
1717
1818COMMON_DOCSTRINGS = {
@@ -534,8 +534,7 @@ def use_alias(**aliases):
534534 >>> my_module(region="bla", projection="meh", J="bla")
535535 Traceback (most recent call last):
536536 ...
537- pygmt.exceptions.GMTInvalidInput:
538- Parameters in short-form (J) and long-form (projection) can't coexist.
537+ pygmt.exceptions.GMTParameterError: Mutually exclusive parameters: ...
539538 """
540539
541540 def alias_decorator (module_func ):
@@ -550,11 +549,10 @@ def new_module(*args, **kwargs):
550549 """
551550 for short_param , long_alias in aliases .items ():
552551 if long_alias in kwargs and short_param in kwargs :
553- msg = (
554- f"Parameters in short-form ( { short_param } ) and "
555- f"long -form ( { long_alias } ) can't coexist."
552+ raise GMTParameterError (
553+ at_most_one = { long_alias , short_param },
554+ reason = f"Long -form parameter { long_alias !r } is recommended." ,
556555 )
557- raise GMTInvalidInput (msg )
558556 if long_alias in kwargs :
559557 kwargs [short_param ] = kwargs .pop (long_alias )
560558 elif short_param in kwargs :
@@ -802,9 +800,9 @@ def deprecate_parameter(oldname, newname, deprecate_version, remove_version):
802800 ... assert issubclass(w[i].category, FutureWarning)
803801 ... assert "deprecated" in str(w[i].message)
804802 data=table.txt, size=5.0, color=red
805- >>> # using both old and new names will raise an GMTInvalidInput exception
803+ >>> # using both old and new names will raise an GMTParameterError exception
806804 >>> import pytest
807- >>> with pytest.raises(GMTInvalidInput ):
805+ >>> with pytest.raises(GMTParameterError ):
808806 ... module(data="table.txt", size=5.0, sizes=4.0)
809807 """
810808
@@ -821,8 +819,10 @@ def new_module(*args, **kwargs):
821819 """
822820 if oldname in kwargs :
823821 if newname in kwargs :
824- msg = f"Can't provide both '{ newname } ' and '{ oldname } '."
825- raise GMTInvalidInput (msg )
822+ raise GMTParameterError (
823+ at_most_one = {newname , oldname },
824+ reason = f"{ oldname !r} is deprecated and { newname !r} is recommended." ,
825+ )
826826 msg = (
827827 f"The '{ oldname } ' parameter has been deprecated since { deprecate_version } "
828828 f" and will be removed in { remove_version } ."
0 commit comments