Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
_py_util.py75 linesDownload Raw Back to engine
1# engine/_py_util.py
2# Copyright (C) 2005-2026 the SQLAlchemy authors and contributors
3# <see AUTHORS file>
4#
5# This module is part of SQLAlchemy and is released under
6# the MIT License: https://www.opensource.org/licenses/mit-license.php
7from __future__ import annotations
8
9import typing
10from typing import Any
11from typing import Mapping
12from typing import Optional
13from typing import Tuple
14
15from .. import exc
16
17if typing.TYPE_CHECKING:
18    from .interfaces import _CoreAnyExecuteParams
19    from .interfaces import _CoreMultiExecuteParams
20    from .interfaces import _DBAPIAnyExecuteParams
21    from .interfaces import _DBAPIMultiExecuteParams
22
23
24_no_tuple: Tuple[Any, ...] = ()
25
26
27def _distill_params_20(
28    params: Optional[_CoreAnyExecuteParams],
29) -> _CoreMultiExecuteParams:
30    if params is None:
31        return _no_tuple
32    # Assume list is more likely than tuple
33    elif isinstance(params, list) or isinstance(params, tuple):
34        # collections_abc.MutableSequence): # avoid abc.__instancecheck__
35        if params and not isinstance(params[0], Mapping):
36            raise exc.ArgumentError(
37                "List argument must consist only of dictionaries"
38            )
39
40        return params
41    elif isinstance(params, dict) or isinstance(
42        # only do immutabledict or abc.__instancecheck__ for Mapping after
43        # we've checked for plain dictionaries and would otherwise raise
44        params,
45        Mapping,
46    ):
47        return [params]
48    else:
49        raise exc.ArgumentError("mapping or list expected for parameters")
50
51
52def _distill_raw_params(
53    params: Optional[_DBAPIAnyExecuteParams],
54) -> _DBAPIMultiExecuteParams:
55    if params is None:
56        return _no_tuple
57    elif isinstance(params, list):
58        # collections_abc.MutableSequence): # avoid abc.__instancecheck__
59        if params and not isinstance(params[0], (tuple, Mapping)):
60            raise exc.ArgumentError(
61                "List argument must consist only of tuples or dictionaries"
62            )
63
64        return params
65    elif isinstance(params, (tuple, dict)) or isinstance(
66        # only do abc.__instancecheck__ for Mapping after we've checked
67        # for plain dictionaries and would otherwise raise
68        params,
69        Mapping,
70    ):
71        # cast("Union[List[Mapping[str, Any]], Tuple[Any, ...]]", [params])
72        return [params]  # type: ignore
73    else:
74        raise exc.ArgumentError("mapping or sequence expected for parameters")
75 
codekingpro/portable-devtools · Team Ai