From c12f66f13c38fc0f31ce3096c2338c8357ebad9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Wilczy=C5=84ski?= Date: Thu, 5 Oct 2023 19:21:53 +0200 Subject: [PATCH] fix: Remove unnecessary UUID wrapping when serializing --- deepfriedmarshmallow/jit.py | 9 ++++++--- pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/deepfriedmarshmallow/jit.py b/deepfriedmarshmallow/jit.py index 6d0c7b8..a913a18 100644 --- a/deepfriedmarshmallow/jit.py +++ b/deepfriedmarshmallow/jit.py @@ -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" diff --git a/pyproject.toml b/pyproject.toml index 5435114..8c31aa8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 ", "Roy Williams "] readme = "README.md" homepage = "https://github.com/mLupine/DeepFriedMarshmallow"