)
-# _is_mapping_or_tuple could be inlined if pure python perf is a problem
+@cython.inline
+@cython.cfunc
+def _is_mapping(value: object, /) -> cython.bint:
+ return (
+ isinstance(value, dict)
+ or isinstance(value, Mapping)
+ # only do immutabledict or abc.__instancecheck__ for Mapping after
+ # we've checked for plain dictionaries and would otherwise raise
+ )
+
+
def _distill_params_20(
params: Optional[_CoreAnyExecuteParams],
) -> _CoreMultiExecuteParams:
"future SQLAlchemy release",
"2.1",
)
- elif not _is_mapping_or_tuple(params[0]):
+ elif not _is_mapping(params[0]):
raise exc.ArgumentError(
- "List argument must consist only of tuples or dictionaries"
+ "List argument must consist only of dictionaries"
)
return params
- elif isinstance(params, dict) or isinstance(params, Mapping):
- # only do immutabledict or abc.__instancecheck__ for Mapping after
- # we've checked for plain dictionaries and would otherwise raise
- return [params]
+ elif _is_mapping(params):
+ return [params] # type: ignore[list-item]
else:
raise exc.ArgumentError("mapping or list expected for parameters")
+# _is_mapping_or_tuple could be inlined if pure python perf is a problem
def _distill_raw_params(
params: Optional[_DBAPIAnyExecuteParams],
) -> _DBAPIMultiExecuteParams:
eq_(self.module._distill_params_20(()), ())
eq_(self.module._distill_params_20([]), [])
- def test_distill_20_sequence_sequence(self):
- eq_(self.module._distill_params_20(((1, 2, 3),)), ((1, 2, 3),))
- eq_(self.module._distill_params_20([(1, 2, 3)]), [(1, 2, 3)])
-
- eq_(self.module._distill_params_20(((1, 2), (2, 3))), ((1, 2), (2, 3)))
- eq_(self.module._distill_params_20([(1, 2), (2, 3)]), [(1, 2), (2, 3)])
-
def test_distill_20_sequence_dict(self):
eq_(self.module._distill_params_20(({"a": 1},)), ({"a": 1},))
eq_(
(MappingProxyType({"a": 1}),),
)
- def test_distill_20_sequence_error(self):
- with expect_raises_message(
- exc.ArgumentError,
- "List argument must consist only of tuples or dictionaries",
- ):
- self.module._distill_params_20((1, 2, 3))
+ @combinations(
+ [(1, 2, 3)],
+ [([1, 2, 3],)],
+ [[1, 2, 3]],
+ [["a", "b"]],
+ [((1, 2, 3),)],
+ [[(1, 2, 3)]],
+ [((1, 2), (2, 3))],
+ [[(1, 2), (2, 3)]],
+ argnames="arg",
+ )
+ def test_distill_20_sequence_error(self, arg):
with expect_raises_message(
exc.ArgumentError,
- "List argument must consist only of tuples or dictionaries",
- ):
- self.module._distill_params_20(([1, 2, 3],))
- with expect_raises_message(
- exc.ArgumentError,
- "List argument must consist only of tuples or dictionaries",
- ):
- self.module._distill_params_20([1, 2, 3])
- with expect_raises_message(
- exc.ArgumentError,
- "List argument must consist only of tuples or dictionaries",
+ "List argument must consist only of dictionaries",
):
- self.module._distill_params_20(["a", "b"])
+ self.module._distill_params_20(arg)
def test_distill_20_dict(self):
eq_(self.module._distill_params_20({"foo": "bar"}), [{"foo": "bar"}])
def none_20(self):
self.impl._distill_params_20(None)
- @test_case
- def list_20(self):
- self.impl._distill_params_20(self.list_tup)
-
- @test_case
- def tuple_20(self):
- self.impl._distill_params_20(self.tup_tup)
-
@test_case
def list_dict_20(self):
- self.impl._distill_params_20(self.list_tup)
+ self.impl._distill_params_20(self.list_dic)
@test_case
def tuple_dict_20(self):
- self.impl._distill_params_20(self.dict)
+ self.impl._distill_params_20(self.tup_dic)
@test_case
def mapping_20(self):
self.impl._distill_params_20(self.mapping)
+ @test_case
+ def dict_20(self):
+ self.impl._distill_params_20(self.dict)
+
@test_case
def raw_none(self):
self.impl._distill_raw_params(None)
@test_case
def raw_list_dict(self):
- self.impl._distill_raw_params(self.list_tup)
+ self.impl._distill_raw_params(self.list_dic)
@test_case
def raw_tuple_dict(self):
- self.impl._distill_raw_params(self.dict)
+ self.impl._distill_raw_params(self.tup_dic)
@test_case
def raw_mapping(self):
self.impl._distill_raw_params(self.mapping)
+ @test_case
+ def raw_dict(self):
+ self.impl._distill_raw_params(self.mapping)
+
class AnonMap(Case):
NUMBER = 5_000_000