From 6a941f58aec3b3fd23553e7442f6744a42923794 Mon Sep 17 00:00:00 2001 From: Harut Date: Mon, 13 Mar 2017 11:05:28 +0300 Subject: [PATCH] splitted field compilation into two methods so we can easily hack it in subclasses --- serpy/serializer.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/serpy/serializer.py b/serpy/serializer.py index affc082..1754ad5 100644 --- a/serpy/serializer.py +++ b/serpy/serializer.py @@ -34,14 +34,15 @@ def _get_fields(direct_fields, serializer_cls): if issubclass(cls, SerializerBase): field_map.update(cls._field_map) field_map.update(direct_fields) + return field_map - compiled_fields = [ + @staticmethod + def _compile_fields(field_map, serializer_cls): + return [ _compile_field_to_tuple(field, name, serializer_cls) for name, field in field_map.items() ] - return field_map, compiled_fields - def __new__(cls, name, bases, attrs): # Fields declared directly on the class. direct_fields = {} @@ -55,7 +56,8 @@ def __new__(cls, name, bases, attrs): real_cls = super(SerializerMeta, cls).__new__(cls, name, bases, attrs) - field_map, compiled_fields = cls._get_fields(direct_fields, real_cls) + field_map = cls._get_fields(direct_fields, real_cls) + compiled_fields = cls._compile_fields(field_map, real_cls) real_cls._field_map = field_map real_cls._compiled_fields = tuple(compiled_fields)