@@ -193,15 +193,15 @@ def restrict_in_place(self, restriction):
193193
194194 def __and__ (self , restriction ):
195195 """
196- Restriction operator
196+ Restriction operator e.g. q1 & q2.
197197 :return: a restricted copy of the input argument
198198 See QueryExpression.restrict for more detail.
199199 """
200200 return self .restrict (restriction )
201201
202202 def __xor__ (self , restriction ):
203203 """
204- Restriction operator ignoring compatibility check.
204+ Permissive restriction operator ignoring compatibility check e.g. q1 ^ q2 .
205205 """
206206 if inspect .isclass (restriction ) and issubclass (restriction , QueryExpression ):
207207 restriction = restriction ()
@@ -211,22 +211,33 @@ def __xor__(self, restriction):
211211
212212 def __sub__ (self , restriction ):
213213 """
214- Inverted restriction
214+ Inverted restriction e.g. q1 - q2.
215215 :return: a restricted copy of the input argument
216216 See QueryExpression.restrict for more detail.
217217 """
218218 return self .restrict (Not (restriction ))
219219
220220 def __neg__ (self ):
221+ """
222+ Convert between restriction and inverted restriction e.g. -q1.
223+ :return: target restriction
224+ See QueryExpression.restrict for more detail.
225+ """
221226 if isinstance (self , Not ):
222227 return self .restriction
223228 return Not (self )
224229
225230 def __mul__ (self , other ):
226- """ join of query expressions `self` and `other` """
231+ """
232+ join of query expressions `self` and `other` e.g. q1 * q2.
233+ """
227234 return self .join (other )
228235
229236 def __matmul__ (self , other ):
237+ """
238+ Permissive join of query expressions `self` and `other` ignoring compatibility check
239+ e.g. q1 @ q2.
240+ """
230241 if inspect .isclass (other ) and issubclass (other , QueryExpression ):
231242 other = other () # instantiate
232243 return self .join (other , semantic_check = False )
@@ -271,7 +282,7 @@ def join(self, other, semantic_check=True, left=False):
271282 return result
272283
273284 def __add__ (self , other ):
274- """union"""
285+ """union e.g. q1 + q2. """
275286 return Union .create (self , other )
276287
277288 def proj (self , * attributes , ** named_attributes ):
@@ -424,7 +435,7 @@ def tail(self, limit=25, **fetch_kwargs):
424435 return self .fetch (order_by = "KEY DESC" , limit = limit , ** fetch_kwargs )[::- 1 ]
425436
426437 def __len__ (self ):
427- """ :return: number of elements in the result set """
438+ """:return: number of elements in the result set e.g. len(q1). """
428439 return self .connection .query (
429440 'SELECT count(DISTINCT {fields}) FROM {from_}{where}' .format (
430441 fields = self .heading .as_sql (self .primary_key , include_aliases = False ),
@@ -433,7 +444,8 @@ def __len__(self):
433444
434445 def __bool__ (self ):
435446 """
436- :return: True if the result is not empty. Equivalent to len(self) > 0 but often faster.
447+ :return: True if the result is not empty. Equivalent to len(self) > 0 but often
448+ faster e.g. bool(q1).
437449 """
438450 return bool (self .connection .query (
439451 'SELECT EXISTS(SELECT 1 FROM {from_}{where})' .format (
@@ -442,19 +454,30 @@ def __bool__(self):
442454
443455 def __contains__ (self , item ):
444456 """
445- returns True if item is found in the .
457+ returns True if a restriction results with any records e.g. restriction in q1 .
446458 :param item: any restriction
447459 (item in query_expression) is equivalent to bool(query_expression & item) but may be
448460 executed more efficiently.
449461 """
450462 return bool (self & item ) # May be optimized e.g. using an EXISTS query
451463
452464 def __iter__ (self ):
465+ """
466+ returns an iterator-compatible QueryExpression object e.g. iter(q1).
467+
468+ :param self: iterator-compatible QueryExpression object
469+ """
453470 self ._iter_only_key = all (v .in_key for v in self .heading .attributes .values ())
454471 self ._iter_keys = self .fetch ('KEY' )
455472 return self
456473
457474 def __next__ (self ):
475+ """
476+ returns the next record on an iterator-compatible QueryExpression object
477+ e.g. next(q1).
478+
479+ :param self: fetch1 record
480+ """
458481 try :
459482 key = self ._iter_keys .pop (0 )
460483 except AttributeError :
@@ -490,6 +513,11 @@ def cursor(self, offset=0, limit=None, order_by=None, as_dict=False):
490513 return self .connection .query (sql , as_dict = as_dict )
491514
492515 def __repr__ (self ):
516+ """
517+ returns the string representation of a QueryExpression object e.g. str(q1).
518+
519+ :param self: String version of query result
520+ """
493521 return super ().__repr__ () if config ['loglevel' ].lower () == 'debug' else self .preview ()
494522
495523 def preview (self , limit = None , width = None ):
0 commit comments