Opened 20 months ago
Closed 20 months ago
#26145 closed defect (fixed)
py3: hashing of cartesian product elements
Reported by:  dkrenn  Owned by:  

Priority:  major  Milestone:  sage8.4 
Component:  python3  Keywords:  
Cc:  Merged in:  
Authors:  Frédéric Chapoton  Reviewers:  Travis Scrimshaw 
Report Upstream:  N/A  Work issues:  
Branch:  bc571fd (Commits)  Commit:  bc571fdd3a6f7742b6e6e6e151bfece1e46e624f 
Dependencies:  Stopgaps: 
Description (last modified by )
part of #24551
sage: C = cartesian_product([ZZ,ZZ]) sage: b = C((1,1)) sage: hash(b)  TypeError Traceback (most recent call last) <ipythoninput1b09cf2f9caf6> in <module>() 1 C = cartesian_product([ZZ,ZZ]) 2 b = C((Integer(1),Integer(1))) > 3 hash(b) TypeError: unhashable type: 'CartesianProduct_with_category.element_class'
Change History (12)
comment:1 Changed 20 months ago by
 Description modified (diff)
comment:2 followup: ↓ 10 Changed 20 months ago by
comment:3 Changed 20 months ago by
 Description modified (diff)
comment:4 Changed 20 months ago by
 Cc jdemeyer added
Looks similar to the problem here:
sage: w = Word([0,1,1,0]) sage: type(w) <class 'sage.combinat.words.word.FiniteWord_list'> sage: w.__eq__ <methodwrapper '__eq__' of FiniteWord_list object at 0x7f840419ec78> sage: w.__hash__
Maybe there is something to change in the way cython handles the __richcmp__
methods ?
comment:5 Changed 20 months ago by
 Branch set to u/chapoton/hash_cartesian
 Cc jdemeyer removed
 Commit set to dc1d70472f1637aacc6e080da16c02c9096862c8
 Status changed from new to needs_review
New commits:
dc1d704  py3: hash for Cartesian product elements

comment:6 Changed 20 months ago by
 Status changed from needs_review to needs_work
comment:7 Changed 20 months ago by
 Commit changed from dc1d70472f1637aacc6e080da16c02c9096862c8 to bc571fdd3a6f7742b6e6e6e151bfece1e46e624f
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
bc571fd  py3: hash for Cartesian product elements

comment:8 Changed 20 months ago by
 Status changed from needs_work to needs_review
comment:9 Changed 20 months ago by
 Reviewers set to Travis Scrimshaw
 Status changed from needs_review to positive_review
LGTM.
comment:10 in reply to: ↑ 2 Changed 20 months ago by
Replying to chapoton:
indeed, hash does not exist, even if it appears in the tab completion: [...]
Fix LGTM, but can someone explain what is going on: The class ElementWrapper
has a __hash__
defined; the class ElementWrapperCheckWrappedClass
is derived from ElementWrapper
, so there should be the same __hash__
used. Why does this not work (with Py3)?
comment:11 Changed 20 months ago by
Probably because it redefines comparison __richcmp__
, which itself is used by Cython to redefine __eq__
.. just a guess..
comment:12 Changed 20 months ago by
 Branch changed from u/chapoton/hash_cartesian to bc571fdd3a6f7742b6e6e6e151bfece1e46e624f
 Resolution set to fixed
 Status changed from positive_review to closed
indeed, hash does not exist, even if it appears in the tab completion: