Check out new cars at Yahoo! Autos. ">

(original) (raw)

Hi Raymond,

Thanks for the detailed explanation!

> I'm not sure what your code was doing where the bugfix would cause
> breakage.  If its \_\_getitem\_\_() override returned a meaningful value
> for each element in obj.keys(), then it should have worked fine.  Of
> course, if it was raising an exception or triggering a side-effect,
> then one could argue that the bugfix was working as intended by
> allowing  the subclasser to affect how the base class goes about its
> business.

It wasn't actually my own code, but that of a colleague. His
\_\_getitem\_\_() override is below. It fails because \_\_getitem\_\_() is
called with the wrong type of argument (plain int instead of a list of
atoms). I'm not sure it presents a convincing use case. I would have
used composition instead of inheritance in the same situation.

I don't feel competent to join the discussion about the changes in the
pickling behavior, but I feel quite strongly that such a change should
not be introduced in a bug-fix release.

Ralf


  def \_\_getitem\_\_(self, atoms):
    LIST = \[\]
    for atom in atoms:
      attr = 'index'
      if hasattr(atom, 'unique\_index'):
        attr = 'unique\_index'
      LIST.append(getattr(atom, attr))
    key1 = tuple(LIST)
    LIST.reverse()  
    key2 = tuple(LIST)
 
    rc = None
    try:
      rc = dict.\_\_getitem\_\_(self, key1)
    except KeyError, e:
      pass
    try:
      rc = dict.\_\_getitem\_\_(self, key2)
    except KeyError, e:
      pass
    return rc



Ahhh...imagining that irresistible "new car" smell?
Check out new cars at Yahoo! Autos.