Opened 4 years ago
Closed 4 years ago
#26145 closed defect (fixed)
py3: hashing of cartesian product elements
Reported by:  Daniel Krenn  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, GitHub, GitLab)  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 4 years ago by
Description:  modified (diff) 

comment:2 followup: 10 Changed 4 years ago by
comment:3 Changed 4 years ago by
Description:  modified (diff) 

comment:4 Changed 4 years ago by
Cc:  Jeroen Demeyer 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 __richmp__
methods ?
comment:5 Changed 4 years ago by
Authors:  → Frédéric Chapoton 

Branch:  → u/chapoton/hash_cartesian 
Cc:  Jeroen Demeyer removed 
Commit:  → dc1d70472f1637aacc6e080da16c02c9096862c8 
Status:  new → needs_review 
New commits:
dc1d704  py3: hash for Cartesian product elements

comment:6 Changed 4 years ago by
Status:  needs_review → needs_work 

comment:7 Changed 4 years ago by
Commit:  dc1d70472f1637aacc6e080da16c02c9096862c8 → 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 4 years ago by
Status:  needs_work → needs_review 

comment:9 Changed 4 years ago by
Reviewers:  → Travis Scrimshaw 

Status:  needs_review → positive_review 
LGTM.
comment:10 Changed 4 years 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 4 years ago by
Probably because it redefines comparison __richcmp__
, which itself is used by Cython to redefine __eq__
.. just a guess..
comment:12 Changed 4 years ago by
Branch:  u/chapoton/hash_cartesian → bc571fdd3a6f7742b6e6e6e151bfece1e46e624f 

Resolution:  → fixed 
Status:  positive_review → closed 
indeed, hash does not exist, even if it appears in the tab completion: