我想知道在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
——每个人都将在Python中创建自己的BadValueError
,或者有另一种首选方法?