From 6023d65b404456a916dec99130038e0d18587b03 Mon Sep 17 00:00:00 2001 From: John MacKenzie Date: Wed, 13 Feb 2013 18:20:11 -0600 Subject: [PATCH] Remove DuplicatePropertyError It is sometimes desirable to redefine a property in a subclass (e.g. to override a default value set in parent class). This removes checks for duplicate properties when using a base class derived from schema.DocumentSchema. --- couchdbkit/__init__.py | 7 +++---- couchdbkit/exceptions.py | 4 ---- couchdbkit/schema/base.py | 11 +---------- 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/couchdbkit/__init__.py b/couchdbkit/__init__.py index 796824d..0a2d9ca 100644 --- a/couchdbkit/__init__.py +++ b/couchdbkit/__init__.py @@ -6,10 +6,9 @@ from .version import version_info, __version__ from .resource import RequestFailed, CouchdbResource -from .exceptions import InvalidAttachment, DuplicatePropertyError,\ -BadValueError, MultipleResultsFound, NoResultFound, ReservedWordError,\ -DocsPathNotFound, BulkSaveError, ResourceNotFound, ResourceConflict, \ -PreconditionFailed +from .exceptions import InvalidAttachment, BadValueError, \ +MultipleResultsFound, NoResultFound, ReservedWordError, DocsPathNotFound, \ +BulkSaveError, ResourceNotFound, ResourceConflict, PreconditionFailed from .client import Server, Database, ViewResults from .changes import ChangesStream diff --git a/couchdbkit/exceptions.py b/couchdbkit/exceptions.py index 3e7def1..0b53db3 100644 --- a/couchdbkit/exceptions.py +++ b/couchdbkit/exceptions.py @@ -11,10 +11,6 @@ class InvalidAttachment(Exception): """ raised when an attachment is invalid """ -class DuplicatePropertyError(Exception): - """ exception raised when there is a duplicate - property in a model """ - class BadValueError(Exception): """ exception raised when a value can't be validated or is required """ diff --git a/couchdbkit/schema/base.py b/couchdbkit/schema/base.py index b1d841d..d5a4546 100644 --- a/couchdbkit/schema/base.py +++ b/couchdbkit/schema/base.py @@ -12,8 +12,7 @@ from .properties import value_to_python, \ convert_property, MAP_TYPES_PROPERTIES, ALLOWED_PROPERTY_TYPES, \ LazyDict, LazyList -from ..exceptions import DuplicatePropertyError, ResourceNotFound, \ -ReservedWordError +from ..exceptions import ResourceNotFound, ReservedWordError __all__ = ['ReservedWordError', 'ALLOWED_PROPERTY_TYPES', 'DocumentSchema', @@ -45,10 +44,6 @@ def __new__(cls, name, bases, attrs): for base in bases: if hasattr(base, '_properties'): property_keys = base._properties.keys() - duplicate_properties = defined.intersection(property_keys) - if duplicate_properties: - raise DuplicatePropertyError( - 'Duplicate properties in base class %s already defined: %s' % (base.__name__, list(duplicate_properties))) defined.update(property_keys) properties.update(base._properties) @@ -64,8 +59,6 @@ def __new__(cls, name, bases, attrs): # map properties if isinstance(attr, p.Property): check_reserved_words(attr_name) - if attr_name in defined: - raise DuplicatePropertyError('Duplicate property: %s' % attr_name) properties[attr_name] = attr attr.__property_config__(cls, attr_name) # python types @@ -73,8 +66,6 @@ def __new__(cls, name, bases, attrs): not attr_name.startswith('_') and \ attr_name not in _NODOC_WORDS: check_reserved_words(attr_name) - if attr_name in defined: - raise DuplicatePropertyError('Duplicate property: %s' % attr_name) prop = MAP_TYPES_PROPERTIES[type(attr)](default=attr) properties[attr_name] = prop prop.__property_config__(cls, attr_name)