From: Justin Crown Date: Sat, 4 Jun 2022 20:10:38 +0000 (-0400) Subject: Docs Update - Add **kwargs to CaseInsensitiveComparator docs (#8063) X-Git-Tag: rel_1_4_38~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1936a9590bd7c06a917909c969858255012507ca;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Docs Update - Add **kwargs to CaseInsensitiveComparator docs (#8063) * 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 (cherry picked from commit 1508aed47261fe17180aa12fb312aebb0dd3c615) --- diff --git a/lib/sqlalchemy/ext/hybrid.py b/lib/sqlalchemy/ext/hybrid.py index 8a4a723468..cc0aca6ca3 100644 --- a/lib/sqlalchemy/ext/hybrid.py +++ b/lib/sqlalchemy/ext/hybrid.py @@ -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 diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py index 4ab0c4f29e..826b312938 100644 --- a/lib/sqlalchemy/sql/operators.py +++ b/lib/sqlalchemy/sql/operators.py @@ -217,8 +217,8 @@ class Operators(object): 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