From e34ca0706ede2dc7f3cca27a2a767b113bfa2c50 Mon Sep 17 00:00:00 2001 From: Vova Abdrakhmanov <369565@gmail.com> Date: Wed, 21 Oct 2020 14:26:43 +0000 Subject: [PATCH] Improve metaclass __call__ method --- joey/serializers.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/joey/serializers.py b/joey/serializers.py index ae897c0..1d86ac5 100644 --- a/joey/serializers.py +++ b/joey/serializers.py @@ -13,7 +13,11 @@ def get(self, key: Any, default: Any = None): class SerializerMetaclass(ModelMetaclass): - def __call__(cls, obj): + def __call__(cls, obj=None, **kwargs): + if obj is None: + return super(SerializerMetaclass, cls).__call__(**kwargs) + if isinstance(obj, dict): + return cls.parse_obj(obj) return cls.from_orm(obj)