From c375d772dd1170cc3f9334c70772cc2c8b7d88d7 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sat, 4 Apr 2015 15:43:49 +0200 Subject: [PATCH] models: Store field keys in models --- mopidy/models.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mopidy/models.py b/mopidy/models.py index 5cea5723..0da4a51f 100644 --- a/mopidy/models.py +++ b/mopidy/models.py @@ -118,9 +118,12 @@ class Collection(Field): class FieldOwner(type): """Helper to automatically assign field names to descriptors.""" def __new__(cls, name, bases, attrs): + attrs['_fields'] = [] for key, value in attrs.items(): if isinstance(value, Field): + attrs['_fields'].append(key) value._name = key + attrs['_fields'].sort() return super(FieldOwner, cls).__new__(cls, name, bases, attrs) @@ -139,7 +142,7 @@ class ImmutableObject(object): def __init__(self, *args, **kwargs): for key, value in kwargs.items(): - if not hasattr(self, key) or callable(getattr(self, key)): + if key not in self._fields: raise TypeError( '__init__() got an unexpected keyword argument "%s"' % key)