Re: SVN: zope.interface/trunk/ Fix a regression introduced in 3.6.4, that made one zope.app.interface test fail

Gediminas Paulauskas <[email protected]>
Newsgroups gmane.comp.web.zope.devel
Message-ID <CAH+bPggeeyZA_rV9NqurSq3FOxxcsw3Hy9yAVtO_YVo1747kAQ@mail.gmail.com>
2011/8/6 Tres Seaver <[email protected]>:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 08/04/2011 10:18 AM, Gediminas Paulauskas wrote:
>> Log message for revision 122462: Fix a regression introduced in
>> 3.6.4, that made one zope.app.interface test fail
>>
>>
>> Changed: U   zope.interface/trunk/CHANGES.txt U
>> zope.interface/trunk/src/zope/interface/interface.py
>>
>> -=- Modified: zope.interface/trunk/CHANGES.txt
>> ===================================================================
>> --- zope.interface/trunk/CHANGES.txt  2011-08-04 13:44:20 UTC (rev
>> 122461) +++ zope.interface/trunk/CHANGES.txt  2011-08-04 14:18:37 UTC
>> (rev 122462) @@ -11,10 +11,12 @@
>>
>> - Fix testing deprecation warnings issued when tested under Py3K.
>>
>> +- Fix ``InterfaceClass.__hash__`` to match comparison function. +
>> 3.6.4 (2011-07-04) ------------------
>>
>> -- LP 804951:  InterfaceClass instances were unhashable under Python
>> 3.x. +- LP #804951:  InterfaceClass instances were unhashable under
>> Python 3.x.
>>
>> 3.6.3 (2011-05-26) ------------------
>>
>> Modified: zope.interface/trunk/src/zope/interface/interface.py
>> ===================================================================
>> --- zope.interface/trunk/src/zope/interface/interface.py      2011-08-04
>> 13:44:20 UTC (rev 122461) +++
>> zope.interface/trunk/src/zope/interface/interface.py  2011-08-04
>> 14:18:37 UTC (rev 122462) @@ -682,7 +682,8 @@ return (n1 > n2) - (n1
>> < n2)
>>
>> def __hash__(self): -        return hash((self.__name__,
>> self.__module__)) +        return hash((getattr(self, '__name__',
>> ''), +                     getattr(self, '__module__', '')))
>
> I don't think this is a regression -- how do you legitimately create an
> interface without both those attributes?   The point of the comparison
> function is to work even when handed a non-Interface object as one of
> the two terms being compared, which doesn't apply to the case of a hash.
> If there is code in zope.app.interface which is constructing a class
> derived from Interface but which doesn't call Interface.__init__ before
> hashing the instance, that code is *broken*, and should be fixed.

It was my attempt to fix tests that were failing for more than a week,
and it worked. zope.app.interface might be broken, but I couldn't
understand why
it failed, especially the "foreign connection" exception. Here I saw
asymmetry between __eq__ and __hash__, and I still feel that my fix
was better than returning 1.

In addition to zope.app.interface, there was another problem with
Tahoe-LAFS: https://bugs.launchpad.net/zope.interface/+bug/811792 that
Tres helped to solve.

-- 
Gediminas
_______________________________________________
Zope-Dev maillist  -  [email protected]
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.