Skip to content

Commit

Permalink
Merge pull request #18 from johnomotani/better-type-error-message
Browse files Browse the repository at this point in the history
Better error message when wrong type is passed
  • Loading branch information
johnomotani authored Nov 20, 2022
2 parents 12a4ad7 + 9ef3c50 commit c65c091
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion optionsfactory/_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Sequence
from numbers import Number


Expand All @@ -11,7 +12,7 @@ def _checked(value, *, meta=None, name=None):
and (not isinstance(value, meta.value_type))
):
raise TypeError(
f"{value} is not of type {meta.value_type}"
f"{value} is not of type {_stringify_sequence_of_types(meta.value_type)}"
f"{'' if name is None else ' for key=' + str(name)}"
)

Expand Down Expand Up @@ -86,3 +87,10 @@ def _options_table_subsection(options, subsection_name):
result += _options_table_subsection(options, None)

return result


def _stringify_sequence_of_types(types):
if isinstance(types, Sequence):
return tuple(_stringify_sequence_of_types(t) for t in types)
else:
return types.__name__

0 comments on commit c65c091

Please sign in to comment.