Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Base class for bidict exceptions."""
class DuplicationError(BidictException):
"""Base class for exceptions raised when uniqueness is violated."""
class KeyDuplicationError(DuplicationError):
"""Raised when a given key is not unique."""
class ValueDuplicationError(DuplicationError):
"""Raised when a given value is not unique."""
class KeyAndValueDuplicationError(KeyDuplicationError, ValueDuplicationError):
"""
Raised when a given item's key and value are not unique.
return
# key and val each duplicate a different existing item.
if on_dup_kv is RAISE:
raise KeyAndValueDuplicationError(key, val)
elif on_dup_kv is IGNORE:
return
# else on_dup_kv is OVERWRITE. Fall through to return on last line.
elif isdupkey:
if on_dup_key is RAISE:
raise KeyDuplicationError(key)
elif on_dup_key is IGNORE:
return
# else on_dup_key is OVERWRITE. Fall through to return on last line.
elif isdupval:
if on_dup_val is RAISE:
raise ValueDuplicationError(val)
elif on_dup_val is IGNORE:
return
# else on_dup_val is OVERWRITE. Fall through to return on last line.
# else neither isdupkey nor isdupval.
return isdupkey, isdupval, invbyval, fwdbykey