jur9526 / couchdb-python

Automatically exported from code.google.com/p/couchdb-python
Other
0 stars 0 forks source link

ListField.Proxy inheritance from list #172

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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.

Original issue reported on code.google.com by daevaorn on 13 Mar 2011 at 8:57

Attachments:

GoogleCodeExporter commented 9 years ago
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.

Original comment by kxepal on 14 Mar 2011 at 9:17

GoogleCodeExporter commented 9 years ago
I thought about `isinstance` case and some list operations but decided that it 
would be the lesser of evils.

Original comment by daevaorn on 14 Mar 2011 at 9:48

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub. Please continue discussion here:

https://github.com/djc/couchdb-python/issues/172

Original comment by djc.ochtman on 15 Jul 2014 at 7:21