Skip to content

Commit 80281c8

Browse files
zzzeekGerrit Code Review
authored and
Gerrit Code Review
committed
Merge "Minor optimization to the code"
2 parents 2ce1f1d + 629273a commit 80281c8

File tree

10 files changed

+83
-349
lines changed

10 files changed

+83
-349
lines changed

.github/workflows/create-wheels.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
# for python 2.7 visual studio 9 is missing
8888
if: matrix.os != 'windows-latest' || matrix.python-version != '2.7'
8989
run: |
90-
python -c 'from sqlalchemy import cprocessors, cresultproxy, cutils'
90+
python -c 'from sqlalchemy.util import has_compiled_ext; assert has_compiled_ext()'
9191
9292
- name: Test created wheel
9393
# the mock reconnect test seems to fail on the ci in windows
@@ -240,7 +240,7 @@ jobs:
240240
then
241241
pip install greenlet "importlib-metadata;python_version<'3.8'"
242242
pip install -f dist --no-index sqlalchemy
243-
python -c 'from sqlalchemy import cprocessors, cresultproxy, cutils'
243+
python -c 'from sqlalchemy.util import has_compiled_ext; assert has_compiled_ext()'
244244
pip install pytest pytest-xdist ${{ matrix.extra-requires }}
245245
pytest -n2 -q test --nomemory --notimingintensive
246246
else
@@ -349,7 +349,7 @@ jobs:
349349
python --version &&
350350
pip install greenlet \"importlib-metadata;python_version<'3.8'\" &&
351351
pip install -f dist --no-index sqlalchemy &&
352-
python -c 'from sqlalchemy import cprocessors, cresultproxy, cutils' &&
352+
python -c 'from sqlalchemy.util import has_compiled_ext; assert has_compiled_ext()' &&
353353
pip install pytest pytest-xdist ${{ matrix.extra-requires }} &&
354354
pytest -n2 -q test --nomemory --notimingintensive"
355355

lib/sqlalchemy/cextension/utils.c

-249
This file was deleted.

lib/sqlalchemy/engine/util.py

+45-59
Original file line numberDiff line numberDiff line change
@@ -34,63 +34,55 @@ def decorated(fn, self, connection):
3434
_no_kw = util.immutabledict()
3535

3636

37-
def py_fallback():
38-
# TODO: pass the Connection in so that there can be a standard
39-
# method for warning on parameter format
40-
def _distill_params(connection, multiparams, params): # noqa
41-
r"""Given arguments from the calling form \*multiparams, \**params,
42-
return a list of bind parameter structures, usually a list of
43-
dictionaries.
44-
45-
In the case of 'raw' execution which accepts positional parameters,
46-
it may be a list of tuples or lists.
47-
48-
"""
49-
50-
# C version will fail if this assertion is not true.
51-
# assert isinstance(multiparams, tuple)
52-
53-
if not multiparams:
54-
if params:
55-
connection._warn_for_legacy_exec_format()
56-
return [params]
37+
def _distill_params(connection, multiparams, params):
38+
r"""Given arguments from the calling form \*multiparams, \**params,
39+
return a list of bind parameter structures, usually a list of
40+
dictionaries.
41+
42+
In the case of 'raw' execution which accepts positional parameters,
43+
it may be a list of tuples or lists.
44+
45+
"""
46+
47+
if not multiparams:
48+
if params:
49+
connection._warn_for_legacy_exec_format()
50+
return [params]
51+
else:
52+
return []
53+
elif len(multiparams) == 1:
54+
zero = multiparams[0]
55+
if isinstance(zero, (list, tuple)):
56+
if (
57+
not zero
58+
or hasattr(zero[0], "__iter__")
59+
and not hasattr(zero[0], "strip")
60+
):
61+
# execute(stmt, [{}, {}, {}, ...])
62+
# execute(stmt, [(), (), (), ...])
63+
return zero
5764
else:
58-
return []
59-
elif len(multiparams) == 1:
60-
zero = multiparams[0]
61-
if isinstance(zero, (list, tuple)):
62-
if (
63-
not zero
64-
or hasattr(zero[0], "__iter__")
65-
and not hasattr(zero[0], "strip")
66-
):
67-
# execute(stmt, [{}, {}, {}, ...])
68-
# execute(stmt, [(), (), (), ...])
69-
return zero
70-
else:
71-
# this is used by exec_driver_sql only, so a deprecation
72-
# warning would already be coming from passing a plain
73-
# textual statement with positional parameters to
74-
# execute().
75-
# execute(stmt, ("value", "value"))
76-
return [zero]
77-
elif hasattr(zero, "keys"):
78-
# execute(stmt, {"key":"value"})
65+
# this is used by exec_driver_sql only, so a deprecation
66+
# warning would already be coming from passing a plain
67+
# textual statement with positional parameters to
68+
# execute().
69+
# execute(stmt, ("value", "value"))
7970
return [zero]
80-
else:
81-
connection._warn_for_legacy_exec_format()
82-
# execute(stmt, "value")
83-
return [[zero]]
71+
elif hasattr(zero, "keys"):
72+
# execute(stmt, {"key":"value"})
73+
return [zero]
8474
else:
8575
connection._warn_for_legacy_exec_format()
86-
if hasattr(multiparams[0], "__iter__") and not hasattr(
87-
multiparams[0], "strip"
88-
):
89-
return multiparams
90-
else:
91-
return [multiparams]
92-
93-
return locals()
76+
# execute(stmt, "value")
77+
return [[zero]]
78+
else:
79+
connection._warn_for_legacy_exec_format()
80+
if hasattr(multiparams[0], "__iter__") and not hasattr(
81+
multiparams[0], "strip"
82+
):
83+
return multiparams
84+
else:
85+
return [multiparams]
9486

9587

9688
def _distill_cursor_params(connection, multiparams, params):
@@ -161,9 +153,3 @@ def _distill_params_20(params):
161153
return (params,), _no_kw
162154
else:
163155
raise exc.ArgumentError("mapping or sequence expected for parameters")
164-
165-
166-
try:
167-
from sqlalchemy.cutils import _distill_params # noqa
168-
except ImportError:
169-
globals().update(py_fallback())

0 commit comments

Comments
 (0)