From e437520217e20d500d641b95482d49484b1f24a7 Mon Sep 17 00:00:00 2001 From: Timo Tuominen Date: Mon, 1 Sep 2014 17:02:48 +0300 Subject: Generator implementation of class mapping. --- rest_framework/serializers.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'rest_framework') diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 5c33300c..b3db3582 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -633,11 +633,10 @@ def _get_class_mapping(mapping, obj): from the dictionary or None. """ - for baseclass in inspect.getmro(obj.__class__): - val = mapping.get(baseclass) - if val: - return val - return None + return next( + (mapping[cls] for cls in inspect.getmro(obj.__class__) if cls in mapping), + None + ) class ModelSerializer(Serializer): -- cgit v1.2.3