aboutsummaryrefslogtreecommitdiffhomepage
path: root/libs/bidict/_dup.py
diff options
context:
space:
mode:
authormorpheus65535 <[email protected]>2024-03-03 12:15:23 -0500
committerGitHub <[email protected]>2024-03-03 12:15:23 -0500
commit03afeb347075381bcb7fd6036295c9fa4a90d2dc (patch)
tree7c5d72c973d2c8e4ade57391a1c9ad5e94903a46 /libs/bidict/_dup.py
parent9ae684240b5bdd40a870d8122f0e380f8d03a187 (diff)
downloadbazarr-03afeb347075381bcb7fd6036295c9fa4a90d2dc.tar.gz
bazarr-03afeb347075381bcb7fd6036295c9fa4a90d2dc.zip
Updated multiple Python modules (now in libs and custom_libs directories) and React libraries
Diffstat (limited to 'libs/bidict/_dup.py')
-rw-r--r--libs/bidict/_dup.py39
1 files changed, 21 insertions, 18 deletions
diff --git a/libs/bidict/_dup.py b/libs/bidict/_dup.py
index 2ce937ad2..fd25b61ed 100644
--- a/libs/bidict/_dup.py
+++ b/libs/bidict/_dup.py
@@ -1,4 +1,4 @@
-# Copyright 2009-2022 Joshua Bronson. All rights reserved.
+# Copyright 2009-2024 Joshua Bronson. All rights reserved.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -7,12 +7,13 @@
"""Provide :class:`OnDup` and related functionality."""
+from __future__ import annotations
-from enum import Enum
import typing as t
+from enum import Enum
-class OD(Enum):
+class OnDupAction(Enum):
"""An action to take to prevent duplication from occurring."""
#: Raise a :class:`~bidict.DuplicationError`.
@@ -26,33 +27,35 @@ class OD(Enum):
return f'{self.__class__.__name__}.{self.name}'
-RAISE = OD.RAISE
-DROP_OLD = OD.DROP_OLD
-DROP_NEW = OD.DROP_NEW
+RAISE: t.Final[OnDupAction] = OnDupAction.RAISE
+DROP_OLD: t.Final[OnDupAction] = OnDupAction.DROP_OLD
+DROP_NEW: t.Final[OnDupAction] = OnDupAction.DROP_NEW
+
+
+class OnDup(t.NamedTuple):
+ r"""A combination of :class:`~bidict.OnDupAction`\s specifying how to handle various types of duplication.
+ The :attr:`~OnDup.key` field specifies what action to take when a duplicate key is encountered.
-class OnDup(t.NamedTuple('_OnDup', [('key', OD), ('val', OD), ('kv', OD)])):
- r"""A 3-tuple of :class:`OD`\s specifying how to handle the 3 kinds of duplication.
+ The :attr:`~OnDup.val` field specifies what action to take when a duplicate value is encountered.
+
+ In the case of both key and value duplication across two different items,
+ only :attr:`~OnDup.val` is used.
*See also* :ref:`basic-usage:Values Must Be Unique`
(https://bidict.rtfd.io/basic-usage.html#values-must-be-unique)
-
- If *kv* is not specified, *val* will be used for *kv*.
"""
- __slots__ = ()
-
- def __new__(cls, key: OD = DROP_OLD, val: OD = RAISE, kv: t.Optional[OD] = None) -> 'OnDup':
- """Override to provide user-friendly default values."""
- return super().__new__(cls, key, val, kv or val)
+ key: OnDupAction = DROP_OLD
+ val: OnDupAction = RAISE
#: Default :class:`OnDup` used for the
#: :meth:`~bidict.bidict.__init__`,
#: :meth:`~bidict.bidict.__setitem__`, and
#: :meth:`~bidict.bidict.update` methods.
-ON_DUP_DEFAULT = OnDup(key=DROP_OLD, val=RAISE, kv=RAISE)
+ON_DUP_DEFAULT: t.Final[OnDup] = OnDup(key=DROP_OLD, val=RAISE)
#: An :class:`OnDup` whose members are all :obj:`RAISE`.
-ON_DUP_RAISE = OnDup(key=RAISE, val=RAISE, kv=RAISE)
+ON_DUP_RAISE: t.Final[OnDup] = OnDup(key=RAISE, val=RAISE)
#: An :class:`OnDup` whose members are all :obj:`DROP_OLD`.
-ON_DUP_DROP_OLD = OnDup(key=DROP_OLD, val=DROP_OLD, kv=DROP_OLD)
+ON_DUP_DROP_OLD: t.Final[OnDup] = OnDup(key=DROP_OLD, val=DROP_OLD)