summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2022-10-23 23:40:42 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2022-10-23 23:40:42 +0000
commit13766228c19954f8860de6a2401c44a32832ae3e (patch)
treef47e86d5c7507dd03b8f771c5c39b4dbc963c19f /lib/sqlalchemy
parentbb71c5673064f0b124072a29c4f61eec7e4bbaff (diff)
parent25619f27836e80351e078c8badc47b3e0acccf5d (diff)
downloadsqlalchemy-13766228c19954f8860de6a2401c44a32832ae3e.tar.gz
Merge "Add pep 584 to python immutabledict fallback" into main
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/cyextension/immutabledict.pyx7
-rw-r--r--lib/sqlalchemy/util/_py_collections.py14
2 files changed, 18 insertions, 3 deletions
diff --git a/lib/sqlalchemy/cyextension/immutabledict.pyx b/lib/sqlalchemy/cyextension/immutabledict.pyx
index 6ab255311..100287b38 100644
--- a/lib/sqlalchemy/cyextension/immutabledict.pyx
+++ b/lib/sqlalchemy/cyextension/immutabledict.pyx
@@ -32,6 +32,7 @@ class ImmutableDictBase(dict):
__delitem__ = __setitem__ = __setattr__ = _immutable
clear = pop = popitem = setdefault = update = _immutable
+
cdef class immutabledict(dict):
def __repr__(self):
return f"immutabledict({dict.__repr__(self)})"
@@ -118,7 +119,9 @@ cdef class immutabledict(dict):
_immutable_fn(self)
def __or__(self, other):
- return immutabledict(super().__or__(other))
+ return immutabledict(dict.__or__(self, other))
def __ror__(self, other):
- return immutabledict(super().__ror__(other))
+ # NOTE: this is used only in cython 3.x;
+ # version 0.x will call __or__ with args inversed
+ return immutabledict(dict.__ror__(self, other))
diff --git a/lib/sqlalchemy/util/_py_collections.py b/lib/sqlalchemy/util/_py_collections.py
index 488229abb..cd46893a4 100644
--- a/lib/sqlalchemy/util/_py_collections.py
+++ b/lib/sqlalchemy/util/_py_collections.py
@@ -27,6 +27,7 @@ from typing import TypeVar
from typing import Union
_T = TypeVar("_T", bound=Any)
+_S = TypeVar("_S", bound=Any)
_KT = TypeVar("_KT", bound=Any)
_VT = TypeVar("_VT", bound=Any)
@@ -129,8 +130,19 @@ class immutabledict(ImmutableDictBase[_KT, _VT]):
def __repr__(self) -> str:
return "immutabledict(%s)" % dict.__repr__(self)
+ # PEP 584
+ def __ior__(self, __value: Any) -> NoReturn: # type: ignore
+ self._readonly()
-_S = TypeVar("_S", bound=Any)
+ def __or__( # type: ignore[override]
+ self, __value: Mapping[_KT, _VT]
+ ) -> immutabledict[_KT, _VT]:
+ return immutabledict(super().__or__(__value))
+
+ def __ror__( # type: ignore[override]
+ self, __value: Mapping[_KT, _VT]
+ ) -> immutabledict[_KT, _VT]:
+ return immutabledict(super().__ror__(__value))
class OrderedSet(Set[_T]):