Skip to content

Commit

Permalink
Merge pull request #250 from Fatal1ty/avoid-duplications-in-union-unp…
Browse files Browse the repository at this point in the history
…acker

Avoid potential duplications in union unpacker
  • Loading branch information
Fatal1ty authored Sep 26, 2024
2 parents a169324 + 69d7ed6 commit 255ebaf
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mashumaro/core/meta/types/unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,19 @@ def get_method_prefix(self) -> str:

def _add_body(self, spec: ValueSpec, lines: CodeLines) -> None:
ambiguous_unpacker_types = []
unpackers = set()
for type_arg in self.union_args:
unpacker = UnpackerRegistry.get(
spec.copy(type=type_arg, expression="value")
)
if type_arg in (bool, str) and unpacker == "value":
ambiguous_unpacker_types.append(type_arg)
if unpacker in unpackers:
continue
with lines.indent("try:"):
lines.append(f"return {unpacker}")
lines.append("except Exception: pass")
unpackers.add(unpacker)
# if len(ambiguous_unpacker_types) >= 2:
# warnings.warn(
# f"{type_name(spec.builder.cls)}.{spec.field_ctx.name} "
Expand Down

0 comments on commit 255ebaf

Please sign in to comment.