Skip to content

Commit df1b576

Browse files
authored
Merge pull request #114 from mulkieran/use-sequence-abstract-type
Use Sequence instance check for struct and array xformer
2 parents 7688fa9 + b308339 commit df1b576

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/into_dbus_python/_xformer.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
# isort: STDLIB
1919
import functools
20+
from collections.abc import Sequence
2021

2122
# isort: THIRDPARTY
2223
import dbus
@@ -157,9 +158,9 @@ def the_array_func(a_list, *, variant=0):
157158
:returns: a dbus Array of transformed values
158159
:rtype: Array
159160
"""
160-
if isinstance(a_list, dict):
161+
if not isinstance(a_list, Sequence):
161162
raise IntoDPUnexpectedValueError(
162-
f"expected a list for an array but found a dict: {a_list}",
163+
f"expected a list for an array but found something else: {a_list}",
163164
a_list,
164165
)
165166
elements = [func(x) for x in a_list]
@@ -198,10 +199,10 @@ def the_func(a_list, *, variant=0):
198199
:rtype: Struct
199200
:raises IntoDPRuntimeError:
200201
"""
201-
if isinstance(a_list, dict):
202+
if not isinstance(a_list, Sequence):
202203
raise IntoDPUnexpectedValueError(
203204
f"expected a simple sequence for the fields of a struct "
204-
f"but found a dict: {a_list}",
205+
f"but found something else: {a_list}",
205206
a_list,
206207
)
207208
if len(a_list) != len(funcs):

tests/test_deterministic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_bad_struct_value(self):
5151
Verify that transforming a dict when a struct is expected fails.
5252
"""
5353
with self.assertRaises(IntoDPUnexpectedValueError):
54-
xformer("(qq)")({})
54+
xformer("(qq)")(({32: 1, 64: 32},))
5555

5656
def test_variant_depth(self):
5757
"""

0 commit comments

Comments
 (0)