]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Docs Update - Add **kwargs to CaseInsensitiveComparator docs (#8063)
authorJustin Crown <justincrown1@gmail.com>
Sat, 4 Jun 2022 20:10:38 +0000 (16:10 -0400)
committerGitHub <noreply@github.com>
Sat, 4 Jun 2022 20:10:38 +0000 (22:10 +0200)
* Add **kwargs to CaseInsensitiveComparator docs

* add kwargs to other operate examples

Change-Id: I70a1e68bca27c2355ad3b7c5bbc538027f112bd9

* missed one entry

Change-Id: Ieb4a18ab6d96e588e9ec7672cfa65fe2fd8301e5

Co-authored-by: Federico Caselli <cfederico87@gmail.com>
lib/sqlalchemy/ext/hybrid.py
lib/sqlalchemy/sql/operators.py

index accfa8949ce5bc7909ec87826794d0df8834e0bf..cfc6bd73b026807b26f70d8cc9b01459c830dfb3 100644 (file)
@@ -484,8 +484,12 @@ lowercasing can be applied to all comparison operations (i.e. ``eq``,
 ``lt``, ``gt``, etc.) using :meth:`.Operators.operate`::
 
     class CaseInsensitiveComparator(Comparator):
-        def operate(self, op, other):
-            return op(func.lower(self.__clause_element__()), func.lower(other))
+        def operate(self, op, other, **kwargs):
+            return op(
+                func.lower(self.__clause_element__()),
+                func.lower(other),
+                **kwargs,
+            )
 
 .. _hybrid_reuse_subclass:
 
@@ -575,10 +579,10 @@ Replacing the previous ``CaseInsensitiveComparator`` class with a new
             else:
                 self.word = func.lower(word)
 
-        def operate(self, op, other):
+        def operate(self, op, other, **kwargs):
             if not isinstance(other, CaseInsensitiveWord):
                 other = CaseInsensitiveWord(other)
-            return op(self.word, other.word)
+            return op(self.word, other.word, **kwargs)
 
         def __clause_element__(self):
             return self.word
@@ -706,12 +710,14 @@ the ``Node.parent`` attribute and filtered based on the given criterion::
     from sqlalchemy.ext.hybrid import Comparator
 
     class GrandparentTransformer(Comparator):
-        def operate(self, op, other):
+        def operate(self, op, other, **kwargs):
             def transform(q):
                 cls = self.__clause_element__()
                 parent_alias = aliased(cls)
-                return q.join(parent_alias, cls.parent).\
-                            filter(op(parent_alias.parent, other))
+                return q.join(parent_alias, cls.parent).filter(
+                    op(parent_alias.parent, other, **kwargs)
+                )
+
             return transform
 
     Base = declarative_base()
@@ -783,8 +789,8 @@ class::
                 return q.join(self.parent_alias, Node.parent)
             return go
 
-        def operate(self, op, other):
-            return op(self.parent_alias.parent, other)
+        def operate(self, op, other, **kwargs):
+            return op(self.parent_alias.parent, other, **kwargs)
 
 .. sourcecode:: pycon+sql
 
index 59345443218c6f152270b1d60179e14beca73d4f..2b888769a1486d32403cde9603ec3e82e096c960 100644 (file)
@@ -320,8 +320,8 @@ class Operators:
         side::
 
             class MyComparator(ColumnOperators):
-                def operate(self, op, other):
-                    return op(func.lower(self), func.lower(other))
+                def operate(self, op, other, **kwargs):
+                    return op(func.lower(self), func.lower(other), **kwargs)
 
         :param op:  Operator callable.
         :param \*other: the 'other' side of the operation. Will