diff options
| author | Justin Crown <justincrown1@gmail.com> | 2022-06-04 16:10:38 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-04 22:10:38 +0200 |
| commit | 1508aed47261fe17180aa12fb312aebb0dd3c615 (patch) | |
| tree | 26fabee0731926701dce39dc19e15c2cf5775f46 /lib/sqlalchemy/ext | |
| parent | cdafd5bb865e867660238b61e727d33ef6f42b37 (diff) | |
| download | sqlalchemy-1508aed47261fe17180aa12fb312aebb0dd3c615.tar.gz | |
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 <cfederico87@gmail.com>
Diffstat (limited to 'lib/sqlalchemy/ext')
| -rw-r--r-- | lib/sqlalchemy/ext/hybrid.py | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/sqlalchemy/ext/hybrid.py b/lib/sqlalchemy/ext/hybrid.py index accfa8949..cfc6bd73b 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 |
