[Zope-dev] SVN: zope.interface/trunk/ Fix a regression introduced in 3.6.4, that made one zope.app.interface test fail

Tres Seaver tseaver at palladion.com
Thu Aug 18 15:45:50 EDT 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 08/17/2011 12:01 PM, Gediminas Paulauskas wrote:
> 2011/8/6 Tres Seaver <tseaver at palladion.com>:
>> -----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.

For the relevant case (an instance whose '__name__' and '__module__'
attributes were not set) your fix returned the hash of '('', '')', which
is hardly an improvement over another fixed constant.  The changes I
checked into zope.app.interface make the PersistentInterface class do
its equality testing / hashing based on its _p_jar and _p_oid:

  http://svn.zope.org/zope.app.interface/trunk/?rev=122544&view=rev

> 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.

The new releases don't really "solve" their problem:  they still have
code which tries to store derived interface obejcts into a module-scope
dist from within the instance's '__new__'.  That code is still broken
(the objects won't be findable in the dict later), but it no longer
raises exceptions during module imoprt:  instead, it issues a UserWarning.


Tres.
- -- 
===================================================================
Tres Seaver          +1 540-429-0999          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk5Na+0ACgkQ+gerLs4ltQ5PEACfUITfcCYeHGJpH/IAAUeP4Bfx
CAIAn3W8hYltSft2UPSbjnNgYL2NpCZt
=lP14
-----END PGP SIGNATURE-----



More information about the Zope-Dev mailing list