Define a 'unary' expression. A unary expression has a single column expression and an operator. The operator can be placed on the left (where it is called the 'operator') or right (where it is called the 'modifier') of the column expression. :class:`.UnaryExpression` is the ba
| 3886 | |
| 3887 | |
| 3888 | class UnaryExpression(ColumnElement[_T]): |
| 3889 | """Define a 'unary' expression. |
| 3890 | |
| 3891 | A unary expression has a single column expression |
| 3892 | and an operator. The operator can be placed on the left |
| 3893 | (where it is called the 'operator') or right (where it is called the |
| 3894 | 'modifier') of the column expression. |
| 3895 | |
| 3896 | :class:`.UnaryExpression` is the basis for several unary operators |
| 3897 | including those used by :func:`.desc`, :func:`.asc`, :func:`.distinct`, |
| 3898 | :func:`.nulls_first` and :func:`.nulls_last`. |
| 3899 | |
| 3900 | """ |
| 3901 | |
| 3902 | __visit_name__ = "unary" |
| 3903 | |
| 3904 | _traverse_internals: _TraverseInternalsType = [ |
| 3905 | ("element", InternalTraversal.dp_clauseelement), |
| 3906 | ("operator", InternalTraversal.dp_operator), |
| 3907 | ("modifier", InternalTraversal.dp_operator), |
| 3908 | ] |
| 3909 | |
| 3910 | element: ColumnElement[Any] |
| 3911 | operator: Optional[OperatorType] |
| 3912 | modifier: Optional[OperatorType] |
| 3913 | |
| 3914 | def __init__( |
| 3915 | self, |
| 3916 | element: ColumnElement[Any], |
| 3917 | *, |
| 3918 | operator: Optional[OperatorType] = None, |
| 3919 | modifier: Optional[OperatorType] = None, |
| 3920 | type_: Optional[_TypeEngineArgument[_T]] = None, |
| 3921 | wraps_column_expression: bool = False, # legacy, not used as of 2.0.42 |
| 3922 | ): |
| 3923 | self.operator = operator |
| 3924 | self.modifier = modifier |
| 3925 | self._propagate_attrs = element._propagate_attrs |
| 3926 | self.element = element.self_group( |
| 3927 | against=self.operator or self.modifier |
| 3928 | ) |
| 3929 | |
| 3930 | # if type is None, we get NULLTYPE, which is our _T. But I don't |
| 3931 | # know how to get the overloads to express that correctly |
| 3932 | self.type = type_api.to_instance(type_) # type: ignore |
| 3933 | |
| 3934 | def _wraps_unnamed_column(self): |
| 3935 | ungrouped = self.element._ungroup() |
| 3936 | return ( |
| 3937 | not isinstance(ungrouped, NamedColumn) |
| 3938 | or ungrouped._non_anon_label is None |
| 3939 | ) |
| 3940 | |
| 3941 | @classmethod |
| 3942 | def _create_nulls_first( |
| 3943 | cls, |
| 3944 | column: _ColumnExpressionArgument[_T], |
| 3945 | ) -> UnaryExpression[_T]: |
no outgoing calls