couchdb-python
couchdb-python copied to clipboard
ListField.Proxy inheritance from list
From daevaorn on March 13, 2011 21:57:38
Now Proxy
is subclass of standard list. But this is not necessary. Proxy
have complete set of methods that implements list interface just fine by using its list
attribute.
It will be better to make Proxy subclass of the plain object
. This will help to catch some interface incompatibility and make cleaner object model. I understand it by discovering #171 issue.
Patch is attached. There is no additional tests because already present ones have passed and it don't require any other.
Attachment: list-field-proxy-inheritance.diff
Original issue: http://code.google.com/p/couchdb-python/issues/detail?id=172
From kxepal on March 14, 2011 14:17:32
For example:
class Test(Document): data = ListField(TextField()) doc = Test() doc.data = ['1', '2', '3']
First test:
assert isinstance(doc.data, list), 'ooops (:' if previously you could used some function which expects only list type, so now you must explicitly convert ListField to list object, but before that you'll spent some time with debug mode on.
heapq.heappush(doc.data, '7') # failed, list expected
also you apply this patch you will make no more such trick:
doc.data += ['4', '5', '6'] doc.data *= 2
and many others. However, this patch shows a lot of flaws of current ListField implementation - all my cons are working, except first one, but without any excepted result. It must have be for sure.
From daevaorn on March 14, 2011 14:48:30
I thought about isinstance
case and some list operations but decided that it would be the lesser of evils.