Skip to content

Commit

Permalink
Merge pull request #114 from mulkieran/use-sequence-abstract-type
Browse files Browse the repository at this point in the history
Use Sequence instance check for struct and array xformer
  • Loading branch information
mulkieran authored Nov 28, 2024
2 parents 7688fa9 + b308339 commit df1b576
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/into_dbus_python/_xformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

# isort: STDLIB
import functools
from collections.abc import Sequence

# isort: THIRDPARTY
import dbus
Expand Down Expand Up @@ -157,9 +158,9 @@ def the_array_func(a_list, *, variant=0):
:returns: a dbus Array of transformed values
:rtype: Array
"""
if isinstance(a_list, dict):
if not isinstance(a_list, Sequence):
raise IntoDPUnexpectedValueError(
f"expected a list for an array but found a dict: {a_list}",
f"expected a list for an array but found something else: {a_list}",
a_list,
)
elements = [func(x) for x in a_list]
Expand Down Expand Up @@ -198,10 +199,10 @@ def the_func(a_list, *, variant=0):
:rtype: Struct
:raises IntoDPRuntimeError:
"""
if isinstance(a_list, dict):
if not isinstance(a_list, Sequence):
raise IntoDPUnexpectedValueError(
f"expected a simple sequence for the fields of a struct "
f"but found a dict: {a_list}",
f"but found something else: {a_list}",
a_list,
)
if len(a_list) != len(funcs):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_deterministic.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_bad_struct_value(self):
Verify that transforming a dict when a struct is expected fails.
"""
with self.assertRaises(IntoDPUnexpectedValueError):
xformer("(qq)")({})
xformer("(qq)")(({32: 1, 64: 32},))

def test_variant_depth(self):
"""
Expand Down

0 comments on commit df1b576

Please sign in to comment.