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

Method _construct_for_op

lib/sqlalchemy/sql/elements.py:2871–2915  ·  view source on GitHub ↗
(
        cls,
        left: ColumnElement[Any],
        right: ColumnElement[Any],
        op: OperatorType,
        *,
        type_: TypeEngine[_T],
        negate: Optional[OperatorType] = None,
        modifiers: Optional[Mapping[str, Any]] = None,
    )

Source from the content-addressed store, hash-verified

2869
2870 @classmethod
2871 def _construct_for_op(
2872 cls,
2873 left: ColumnElement[Any],
2874 right: ColumnElement[Any],
2875 op: OperatorType,
2876 *,
2877 type_: TypeEngine[_T],
2878 negate: Optional[OperatorType] = None,
2879 modifiers: Optional[Mapping[str, Any]] = None,
2880 ) -> OperatorExpression[_T]:
2881 if operators.is_associative(op):
2882 assert (
2883 negate is None
2884 ), f"negate not supported for associative operator {op}"
2885
2886 multi = False
2887 if getattr(
2888 left, "operator", None
2889 ) is op and type_._compare_type_affinity(left.type):
2890 multi = True
2891 left_flattened = left._flattened_operator_clauses
2892 else:
2893 left_flattened = (left,)
2894
2895 if getattr(
2896 right, "operator", None
2897 ) is op and type_._compare_type_affinity(right.type):
2898 multi = True
2899 right_flattened = right._flattened_operator_clauses
2900 else:
2901 right_flattened = (right,)
2902
2903 if multi:
2904 return ExpressionClauseList._construct_for_list(
2905 op,
2906 type_,
2907 *(left_flattened + right_flattened),
2908 )
2909
2910 if right._is_collection_aggregate:
2911 negate = None
2912
2913 return BinaryExpression(
2914 left, right, op, type_=type_, negate=negate, modifiers=modifiers
2915 )
2916
2917
2918class ExpressionClauseList(OperatorExpression[_T]):

Callers 2

_boolean_compareFunction · 0.80
_binary_operateFunction · 0.80

Calls 3

BinaryExpressionClass · 0.85
_construct_for_listMethod · 0.80

Tested by

no test coverage detected