Skip to content

Commit

Permalink
Merge pull request #230 from Fatal1ty/remove-warnigns-about-union-amb…
Browse files Browse the repository at this point in the history
…iguity

Remove warnings about union ambiguity
  • Loading branch information
Fatal1ty committed Jun 15, 2024
2 parents 5ab1217 + 9e121bd commit 17f2811
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
16 changes: 8 additions & 8 deletions mashumaro/core/meta/types/unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import types
import typing
import uuid
import warnings
from abc import ABC
from base64 import decodebytes
from contextlib import suppress
Expand Down Expand Up @@ -180,13 +179,14 @@ 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} "
# f"({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 17f2811

Please sign in to comment.