[Checkins] SVN: zope.app.undo/branches/nikhil_n-py25/src/zope/app/undo/__init__.py made zope.app.undo work with Python 2.5

Nikhil N nikhil.n.n at gmail.com
Mon Jul 9 12:38:20 EDT 2007


Hi,

On 7/7/07, Christian Theune <ct at gocept.com> wrote:
>>Benji York <benji at zope.com> wrote:
> > Correct me if I'm wrong, but it looks like __eq__ below could be changed
> > to just
> >
> >      def __eq__(self, other):
> >          return other and unicode(other).startswith(self)
> >
Forgive me for my limited knowledge if so.In the above statement  the
"other"  can also be of None type. Returning None will cause a test
to fail which expects true or false from the function.

> > (Not sure if the call to unicode is even needed, but I don't know what
> > this code is really doing.)

> "unicode(other[:len(self)]).__eq__(self) == 1:" is reeeaaally hard to
> understand without looking very closely. Benji's approach is easily
> understandable.
>
That line truely was hard to understand, me being a beginner in this
field. Also I too think that the unicode here is not needed.

What I just did in that line was to remove the __cmp__ attribute which is
absent in unicode objects from Python2.5 and replace it by __eq__.

My intention  was to port the code to 2.5 with minimum code
changes (while ensuring the correctness)  so that chances of
errors is also minimum.

So I left its major part unchanged.

> Also, the code has quite some redundancy in it, the only difference in
> the "except" block is in the use of __eq__ instead of __cmp__. And it's
> not immediately clear that a missing __cmp__ will trigger the
> AttributeError. There's a lot more going on that *potentially* could
> trigger it. Looking closely it's the onlye likely source though.

Here what  I tried was to ensure backward combatibility with previous
python versions. But I don't think it now as the right way. Perhaps I could
have used the "sys.version_info" in such cases. I would like to know your
opinion about that.

> If startswith() is what you wanted then it becomes even simpler.

Thanks for the suggetion.It made the line work for lower Python
versions also, inaddition to increasing the readability of the code.

The body of the function I will be committing  soon is changed to
 """
  if other and other.startswith(self):
                return True
  return False
"""
Please correct me if I am wrong.

With Regards
Nikhil N


More information about the Checkins mailing list