我想知道在Python中指示无效参数组合的最佳做法。我遇到过几种情况,其中您具有如下功能:
def import_to_orm(name, save=False, recurse=False):
"""
:param name: Name of some external entity to import.
:param save: Save the ORM object before returning.
:param recurse: Attempt to import associated objects as well. Because you
need the original object to have a key to relate to, save must be
`True` for recurse to be `True`.
:raise BadValueError: If `recurse and not save`.
:return: The ORM object.
"""
pass
唯一令人烦恼的是,每个包装都有自己的包装,通常略有不同BadValueError
。我知道在Java中存在java.lang.IllegalArgumentException
-是否众所周知每个人都将BadValueError
在Python中创建自己的s还是存在另一种首选方法?