Skip to content

Commit

Permalink
Remove warnings about union ambiguity
Browse files Browse the repository at this point in the history
  • Loading branch information
Fatal1ty committed Jun 15, 2024
1 parent 5ab1217 commit 2d0ff9a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
14 changes: 7 additions & 7 deletions mashumaro/core/meta/types/unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ def _add_body(self, spec: ValueSpec, lines: CodeLines) -> None:
with lines.indent("try:"):
lines.append(f"return {unpacker}")
lines.append("except Exception: pass")
if len(ambiguous_unpacker_types) >= 2:
warnings.warn(
f"{type_name(spec.builder.cls)}.{spec.field_ctx.name} ({type_name(spec.type)}): "
"In the next release, data marked with Union type containing "
"'str' and 'bool' will be coerced to the value of the type "
"specified first instead of passing it as is"
)
# if len(ambiguous_unpacker_types) >= 2:
# warnings.warn(
# f"{type_name(spec.builder.cls)}.{spec.field_ctx.name} ({type_name(spec.type)}): "
# "In the next release, data marked with Union type containing "
# "'str' and 'bool' will be coerced to the value of the type "
# "specified first instead of passing it as is"
# )
field_type = spec.builder.get_type_name_identifier(
typ=spec.type,
resolved_type_params=spec.builder.get_field_resolved_type_params(
Expand Down
13 changes: 7 additions & 6 deletions tests/test_union.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ def test_union_encoding():
assert same_types(value, encoded)


def test_str_bool_union_warning():
with pytest.warns(UserWarning):

@dataclass
class _(DataClassDictMixin):
x: Union[str, bool]
# TDDO: Convert this to a normal test
# def test_str_bool_union_warning():
# with pytest.warns(UserWarning):
#
# @dataclass
# class _(DataClassDictMixin):
# x: Union[str, bool]

0 comments on commit 2d0ff9a

Please sign in to comment.