diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-01-19 15:34:46 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-01-20 09:13:58 -0500 |
commit | d1eeef5e67fa4632f88a894f0c5cf4445f04ba2b (patch) | |
tree | 30f2ad05dbf45bb2aa5dc33502a24cbdc5281097 /test/sql/test_operators.py | |
parent | e82a5f19e1606500ad4bf6a456c2558d74df24bf (diff) | |
download | sqlalchemy-d1eeef5e67fa4632f88a894f0c5cf4445f04ba2b.tar.gz |
typing updates
The :meth:`_sql.ColumnOperators.in_` and
:meth:`_sql.ColumnOperators.not_in_` are typed to include
``Iterable[Any]`` rather than ``Sequence[Any]`` for more flexibility in
argument type.
The :func:`_sql.or_` and :func:`_sql.and_` from a typing perspective
require the first argument to be present, however these functions still
accept zero arguments which will emit a deprecation warning at runtime.
Typing is also added to support sending the fixed literal ``False`` for
:func:`_sql.or_` and ``True`` for :func:`_sql.and_` as the first argument
only, however the documentation now indicates sending the
:func:`_sql.false` and :func:`_sql.true` constructs in these cases as a
more explicit approach.
Fixed typing issue where iterating over a :class:`_orm.Query` object
was not correctly typed.
Fixes: #9122
Fixes: #9123
Fixes: #9125
Change-Id: I500e3e1b826717b3dd49afa1e682c3c8279c9226
Diffstat (limited to 'test/sql/test_operators.py')
-rw-r--r-- | test/sql/test_operators.py | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py index 103520f1f..d93ba61ba 100644 --- a/test/sql/test_operators.py +++ b/test/sql/test_operators.py @@ -2,6 +2,7 @@ import collections.abc as collections_abc import datetime import operator import pickle +import re from sqlalchemy import and_ from sqlalchemy import between @@ -1401,20 +1402,34 @@ class ConjunctionTest(fixtures.TestBase, testing.AssertsCompiledSQL): dialect=default.DefaultDialect(supports_native_boolean=False), ) - @combinations((and_, "and_", "True"), (or_, "or_", "False")) - def test_empty_clauses(self, op, str_op, str_continue): + @combinations( + (and_, "and_", r"true", "True"), + (or_, "or_", r"false", "False"), + ) + def test_empty_clauses(self, op, str_op, str_continue, str_continue_2): # these warning classes will change to ArgumentError when the # deprecated behavior is disabled with expect_deprecated( - r"Invoking %(str_op)s\(\) without arguments is deprecated, and " - r"will be disallowed in a future release. For an empty " - r"%(str_op)s\(\) construct, use " - r"%(str_op)s\(%(str_continue)s, \*args\)\." - % {"str_op": str_op, "str_continue": str_continue} + re.escape( + f"Invoking {str_op}() without arguments is deprecated, and " + "will be disallowed in a future release. For an empty " + f"{str_op}() construct, use " + f"'{str_op}({str_continue}(), *args)' or " + f"'{str_op}({str_continue_2}, *args)'." + ) ): op() + def test_empty_construct_for_whereclause(self): + eq_(BooleanClauseList._construct_for_whereclause(()), None) + + def test_non_empty_construct_for_whereclause(self): + self.assert_compile( + BooleanClauseList._construct_for_whereclause([column("q") == 5]), + "q = :q_1", + ) + def test_empty_and_raw(self): self.assert_compile( BooleanClauseList._construct_raw(operators.and_), "" |