[sqlalchemy] Re: bug in OrderedDict?

2007-06-02 Thread Michael Bayer

sounds like a bug.  add a ticket and/or create a patch !  thanks.

On Jun 2, 3:48 pm, Eric Ongerth [EMAIL PROTECTED] wrote:
 I noticed that if you pop() an item out of an OrderedDict, then ask
 the OrderedDict for its values(), you get a key error because the OD
 doesn't trim its ._list when the pop() occurs.

 Is this by design?

 (demonstration below)

  import sqlalchemy
  from sqlalchemy.util import OrderedDict

  od=OrderedDict()
  od.update({'id':3L})
  od.update({'mfr':'BD','model_name':'Stigma'})
  od

 {'mfr': 'BD', 'id': 3L, 'model_name': 'Stigma'}

  od.values()

 [3L, 'BD', 'Stigma']

  od.pop('id')

 3L

  od

 {'mfr': 'BD', 'model_name': 'Stigma'}

  od._list

 ['id', 'mfr', 'model_name']

  od.values()

 Traceback (most recent call last):
   File input, line 1, in module
   File H:\Python25\lib\site-packages\sqlalchemy\lib\sqlalchemy
 \util.py, line 243, in values
 return [self[key] for key in self._list]
   File H:\Python25\lib\site-packages\sqlalchemy\lib\sqlalchemy
 \util.py, line 270, in __getitem__
 return dict.__getitem__(self, key)
 KeyError: 'id'


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: bug in OrderedDict?

2007-06-02 Thread Eric Ongerth

done and done: Ticket #585.

Patch reprinted here for the curious passerby:

def pop(self, key=None):
if key == None:
try:
key = self._list[0]
except IndexError:
raise IndexError('tried to pop() from an empty
OrderedDict')
result = self[key]
dict.__delitem__(self, key)
self._list = self._list[1:]
return result
elif not key in self:
raise KeyError(key)
else:
self._list.remove(key)
return dict.pop(self, key)


On Jun 2, 2:30 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 sounds like a bug.  add a ticket and/or create a patch !  thanks.

 On Jun 2, 3:48 pm, Eric Ongerth [EMAIL PROTECTED] wrote:

  I noticed that if you pop() an item out of an OrderedDict, then ask
  the OrderedDict for its values(), you get a key error because the OD
  doesn't trim its ._list when the pop() occurs.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---