MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / custom_op

Class custom_op

lib/sqlalchemy/sql/operators.py:382–495  ·  view source on GitHub ↗

Represent a 'custom' operator. :class:`.custom_op` is normally instantiated when the :meth:`.Operators.op` or :meth:`.Operators.bool_op` methods are used to create a custom operator callable. The class can also be used directly when programmatically constructing expressions. E.g.

Source from the content-addressed store, hash-verified

380
381
382class custom_op(OperatorType, Generic[_T]):
383 """Represent a 'custom' operator.
384
385 :class:`.custom_op` is normally instantiated when the
386 :meth:`.Operators.op` or :meth:`.Operators.bool_op` methods
387 are used to create a custom operator callable. The class can also be
388 used directly when programmatically constructing expressions. E.g.
389 to represent the "factorial" operation::
390
391 from sqlalchemy.sql import UnaryExpression
392 from sqlalchemy.sql import operators
393 from sqlalchemy import Numeric
394
395 unary = UnaryExpression(
396 table.c.somecolumn, modifier=operators.custom_op("!"), type_=Numeric
397 )
398
399 .. seealso::
400
401 :meth:`.Operators.op`
402
403 :meth:`.Operators.bool_op`
404
405 """ # noqa: E501
406
407 __name__ = "custom_op"
408
409 __slots__ = (
410 "opstring",
411 "precedence",
412 "is_comparison",
413 "natural_self_precedent",
414 "eager_grouping",
415 "return_type",
416 "python_impl",
417 )
418
419 def __init__(
420 self,
421 opstring: str,
422 precedence: int = 0,
423 is_comparison: bool = False,
424 return_type: Optional[
425 Union[Type[TypeEngine[_T]], TypeEngine[_T]]
426 ] = None,
427 natural_self_precedent: bool = False,
428 eager_grouping: bool = False,
429 python_impl: Optional[Callable[..., Any]] = None,
430 ):
431 self.opstring = opstring
432 self.precedence = precedence
433 self.is_comparison = is_comparison
434 self.natural_self_precedent = natural_self_precedent
435 self.eager_grouping = eager_grouping
436 self.return_type = (
437 return_type._to_instance(return_type) if return_type else None
438 )
439 self.python_impl = python_impl

Callers 1

opMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected