Skip to content

Commit

Permalink
fix: Remove unnecessary UUID wrapping when serializing
Browse files Browse the repository at this point in the history
  • Loading branch information
mLupine committed Oct 5, 2023
1 parent 58edc7e commit c12f66f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions deepfriedmarshmallow/jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,14 @@ def inline(self, field, context):
"""Generates a template for inlining UUID serialization."""
if is_overridden(field._serialize, marshmallow.fields.UUID._serialize):
return None
result = "uuid.UUID({0})"
result += " if {0} is not None and isinstance({0}, str) else "
result += "({0} if {0} is not None and isinstance({0}, uuid.UUID) else None)"
if not context.is_serializing:
result = "uuid.UUID({0})"
result += " if {0} is not None and isinstance({0}, str) else "
result += "({0} if {0} is not None and isinstance({0}, uuid.UUID) else None)"
result = f"({result})" + " if (isinstance({0}, (uuid.UUID, str)) or {0} is None) else dict()['error']"
else:
result = "str({0})"
result += " if {0} is not None and isinstance({0}, (uuid.UUID, str)) else None"
return result, "uuid"


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "DeepFriedMarshmallow"
version = "1.0.0dev6"
description = "A JIT implementation for Marshmallow to speed up data serialization and deserialization"
description = "A plug-and-play JIT implementation for Marshmallow to speed up data serialization and deserialization"
authors = ["Maciej Wilczynski <[email protected]>", "Roy Williams <[email protected]>"]
readme = "README.md"
homepage = "https://github.com/mLupine/DeepFriedMarshmallow"
Expand Down

0 comments on commit c12f66f

Please sign in to comment.