diff options
| author | Federico Caselli <cfederico87@gmail.com> | 2021-01-01 16:09:01 +0100 |
|---|---|---|
| committer | Federico Caselli <cfederico87@gmail.com> | 2021-12-17 21:29:05 +0100 |
| commit | 76fa211620de167b76846f0e5db5b64b8756ad48 (patch) | |
| tree | c435dbf6585b3758dc78ee82bf114e162a25d0e1 /lib/sqlalchemy/engine/_py_util.py | |
| parent | 3543fcc9c9601e81560d055ceadaea05c75815c0 (diff) | |
| download | sqlalchemy-76fa211620de167b76846f0e5db5b64b8756ad48.tar.gz | |
Replace c extension with cython versions.workflow_test_cython
Re-implement c version immutabledict / processors / resultproxy / utils with cython.
Performance is in general in par or better than the c version
Added a collection module that has cython version of OrderedSet and IdentitySet
Added a new test/perf file to compare the implementations.
Run ``python test/perf/compiled_extensions.py all`` to execute the comparison test.
See results here: https://docs.google.com/document/d/1nOcDGojHRtXEkuy4vNXcW_XOJd9gqKhSeALGG3kYr6A/edit?usp=sharing
Fixes: #7256
Change-Id: I2930ef1894b5048210384728118e586e813f6a76
Signed-off-by: Federico Caselli <cfederico87@gmail.com>
Diffstat (limited to 'lib/sqlalchemy/engine/_py_util.py')
| -rw-r--r-- | lib/sqlalchemy/engine/_py_util.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/sqlalchemy/engine/_py_util.py b/lib/sqlalchemy/engine/_py_util.py new file mode 100644 index 000000000..2db6c049b --- /dev/null +++ b/lib/sqlalchemy/engine/_py_util.py @@ -0,0 +1,54 @@ +from collections import abc as collections_abc + +from .. import exc + +_no_tuple = () + + +def _distill_params_20(params): + if params is None: + return _no_tuple + # Assume list is more likely than tuple + elif isinstance(params, list) or isinstance(params, tuple): + # collections_abc.MutableSequence): # avoid abc.__instancecheck__ + if params and not isinstance( + params[0], (tuple, collections_abc.Mapping) + ): + raise exc.ArgumentError( + "List argument must consist only of tuples or dictionaries" + ) + + return params + elif isinstance(params, dict) or isinstance( + # only do immutabledict or abc.__instancecheck__ for Mapping after + # we've checked for plain dictionaries and would otherwise raise + params, + collections_abc.Mapping, + ): + return [params] + else: + raise exc.ArgumentError("mapping or list expected for parameters") + + +def _distill_raw_params(params): + if params is None: + return _no_tuple + elif isinstance(params, list): + # collections_abc.MutableSequence): # avoid abc.__instancecheck__ + if params and not isinstance( + params[0], (tuple, collections_abc.Mapping) + ): + raise exc.ArgumentError( + "List argument must consist only of tuples or dictionaries" + ) + + return params + elif isinstance(params, (tuple, dict)) or isinstance( + # only do abc.__instancecheck__ for Mapping after we've checked + # for plain dictionaries and would otherwise raise + params, + collections_abc.Mapping, + ): + return [params] + else: + raise exc.ArgumentError("mapping or sequence expected for parameters") |
