"TypeError: unhashable type: 'InterfaceClass'" in Python 3

Bug #804951 reported by Facundo Batista
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
zope.interface
Fix Released
Undecided
Tres Seaver

Bug Description

I got this after installing zope.interface 3.6.3 from the tarball.

The problem is that InterfaceClass defines __eq__ but not __hash__.

I workarounded the problem by adding a

  def __hash__(self):
    return id(self)

...but I don't know if it's a proper solution.

Regards,

Revision history for this message
Tres Seaver (tseaver) wrote :

I don't think 'id(self)' is the right hash value: items which compare equal are also supposed to have the same hash value. Likely we should be using the hash of the fully-qualified name.

Changed in zope.interface:
assignee: nobody → Tres Seaver (tseaver)
status: New → Confirmed
Revision history for this message
Tres Seaver (tseaver) wrote :

To get the buildout bootstrapped under Python3, I did::

 $ svn cat svn://svn.zope.org/repos/main/zc.buildout/branches/2/bootstrap/bootstrap.py > boostrap3.py
 $ /opt/Python-3.2.0/bin/python3 boostrap.py
 ...

Note that the Sphinx dependencies for the 'docs' part won't build, so skip that part::

 $ bin/buildout install test python

but I can't run the tests::

 $ bin/test --all
 Traceback (most recent call last):
   File "bin/test", line 20, in <module>
     import zope.testrunner
   File "/tmp/zi/src/zope.interface/eggs/zope.testrunner-4.0.3-py3.2.egg/zope/testrunner/__init__.py", line 21, in <module>
     import zope.testrunner.interfaces
   File "/tmp/zi/src/zope.interface/eggs/zope.testrunner-4.0.3-py3.2.egg/zope/testrunner/interfaces.py", line 21, in <module>
     import zope.interface
   File "/tmp/zi/src/zope.interface/src/zope/interface/__init__.py", line 53, in <module>
     from zope.interface.interface import Interface, _wire
   File "/tmp/zi/src/zope.interface/src/zope/interface/interface.py", line 577
     exec "class %s: pass" % self.__name__ in klass
                         ^
 SyntaxError: invalid syntax

Revision history for this message
Tres Seaver (tseaver) wrote :

Turns out the only sane way to test zope.interface under Python3 is:

  $ /path/to/nonvirtual/Python-3.x/bin/python3 setup.py test

Revision history for this message
Tres Seaver (tseaver) wrote :

Released a fix with zope.interface 3.6.4:
  http://pypi.python.org/pypi/zope.interface/3.6.4

Changed in zope.interface:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.