我想知道在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中创建自己的BadValueErrors,这是很好理解的,还是有其他的首选方法?