Skip to content

Commit

Permalink
Merge pull request #43 from Harut/split_compile
Browse files Browse the repository at this point in the history
Split _compile_fields
  • Loading branch information
clarkduvall authored Sep 28, 2017
2 parents 3d45f6a + 6a941f5 commit 34dae3e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions serpy/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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)
Expand Down

0 comments on commit 34dae3e

Please sign in to comment.