diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-05-18 16:21:49 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-05-18 16:21:49 -0400 |
commit | deb9bcc0d97dd8b38dfccb340a5fc1f880202ff6 (patch) | |
tree | d7fd735132e8686f60ff811612f019f4bbf9404d /lib/sqlalchemy/sql/operators.py | |
parent | 9e7bed9df601ead02fd96bf2fc787b23b536d2d6 (diff) | |
download | sqlalchemy-deb9bcc0d97dd8b38dfccb340a5fc1f880202ff6.tar.gz |
favor bool_op over op in comparison
there's no need to use the is_comparison parameter
anymore as bool_op() works better and in 2.0 also does
typing correctly.
Change-Id: I9e92b665b112d40d90e539003b0efe00ed7b075f
Diffstat (limited to 'lib/sqlalchemy/sql/operators.py')
-rw-r--r-- | lib/sqlalchemy/sql/operators.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py index 98d763e98..0a8527761 100644 --- a/lib/sqlalchemy/sql/operators.py +++ b/lib/sqlalchemy/sql/operators.py @@ -217,14 +217,17 @@ class Operators: A value of 100 will be higher or equal to all operators, and -100 will be lower than or equal to all operators. - :param is_comparison: if True, the operator will be considered as a - "comparison" operator, that is which evaluates to a boolean - true/false value, like ``==``, ``>``, etc. This flag should be set + :param is_comparison: legacy; if True, the operator will be considered + as a "comparison" operator, that is which evaluates to a boolean + true/false value, like ``==``, ``>``, etc. This flag is provided so that ORM relationships can establish that the operator is a comparison operator when used in a custom join condition. - .. versionadded:: 0.9.2 - added the - :paramref:`.Operators.op.is_comparison` flag. + Using the ``is_comparison`` parameter is superseded by using the + :meth:`.Operators.bool_op` method instead; this more succinct + operator sets this parameter automatically, but also provides + correct :pep:`484` typing support as the returned object will + express a "boolean" datatype, i.e. ``BinaryExpression[bool]``. :param return_type: a :class:`.TypeEngine` class or object that will force the return type of an expression produced by this operator @@ -255,6 +258,8 @@ class Operators: .. seealso:: + :meth:`.Operators.bool_op` + :ref:`types_operators` :ref:`relationship_custom_operator` @@ -284,7 +289,9 @@ class Operators: This method is shorthand for calling :meth:`.Operators.op` and passing the :paramref:`.Operators.op.is_comparison` - flag with True. + flag with True. A key advantage to using :meth:`.Operators.bool_op` + is that when using column constructs, the "boolean" nature of the + returned expression will be present for :pep:`484` purposes. .. seealso:: |