New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
py3: defining __eq__ breaks inheritance of __hash__ #24551
Comments
comment:1
Good to know is that there is a metaclass |
comment:2
I've also, at least, provisionally, implemented There are also lots of cases where it's fine to just assign |
comment:3
ok. But anyway, this seems to require a lot of work.. I did a few simple cases in #24552 |
comment:4
Of the commits in my python 3 branch that I haven't made tickets for yet, I've added
|
comment:5
and its subclasses should never be used in a hash (it is a helper class to perform a bijection) and the |
comment:6
Quick question one of you can maybe answer: If a class inherits from I've found several classes that inherit from
for some list of various attributes of the objects that are mostly determined at the object's construction. I admit I don't fully understand yet how |
comment:7
Or could it be that in some of these cases their |
comment:8
Okay, quoting the docs:
So IIUC, a class really shouldn't be inheriting |
comment:9
Replying to @embray:
That sounds reasonable. |
comment:10
I'm just going through |
comment:11
Another angle to this that Jeroen has already pointed out a couple times is that there is In other words, I think that the new behavior in Python 3, while annoying in terms of how much it breaks in Sage, is good that it forces us to think more carefully about this. So I'd be hesitant to resort to such a brute-force fix except as a last resort. |
comment:12
Among the files listed in the ticket description, the case
is dealt with by #25502.
should trigger no Python3 issue since none of these classes is intended to be hashable. Same thing for
|
comment:14
some failures in sage3 doctests:
|
comment:15
Note that the changes (taken from comment:2) diff --git a/src/sage/groups/abelian_gps/abelian_group.py b/src/sage/groups/abelian_gps/abelian_group.py
index e19199b949..bf6fe5dc2c 100644
--- a/src/sage/groups/abelian_gps/abelian_group.py
+++ b/src/sage/groups/abelian_gps/abelian_group.py
@@ -553,6 +553,8 @@ class AbelianGroup_class(UniqueRepresentation, AbelianGroupBase):
cat = cat.Infinite()
AbelianGroupBase.__init__(self, category=cat)
+ __hash__ = UniqueRepresentation.__hash__
+
def is_isomorphic(left, right):
"""
Check whether ``left`` and ``right`` are isomorphic
diff --git a/src/sage/groups/perm_gps/permgroup_named.py b/src/sage/groups/perm_gps/permgroup_named.py
index da1774e96c..54fa034b4a 100644
--- a/src/sage/groups/perm_gps/permgroup_named.py
+++ b/src/sage/groups/perm_gps/permgroup_named.py
@@ -149,6 +149,8 @@ class PermutationGroup_unique(CachedRepresentation, PermutationGroup_generic):
"""
return super(CachedRepresentation, self).__eq__(other)
+ __hash__ = CachedRepresentation.__hash__
+
class PermutationGroup_symalt(PermutationGroup_unique):
""" fix many Python 3 doctest failures in |
comment:16
If you're using the |
comment:17
That class has the line
so that generator names (for example) don't affect equality. ( (I also don't know how or why the design decisions for |
comment:18
Confirmed: diff --git a/src/sage/groups/abelian_gps/abelian_group.py b/src/sage/groups/abelian_gps/abelian_group.py
index e19199b949..62a5e25edb 100644
--- a/src/sage/groups/abelian_gps/abelian_group.py
+++ b/src/sage/groups/abelian_gps/abelian_group.py
@@ -553,6 +553,9 @@ class AbelianGroup_class(UniqueRepresentation, AbelianGroupBase):
cat = cat.Infinite()
AbelianGroupBase.__init__(self, category=cat)
+ def __hash__(self):
+ return hash(self.elementary_divisors())
+
def is_isomorphic(left, right):
"""
Check whether ``left`` and ``right`` are isomorphic works just as well, at least as far as the homology code is concerned. |
comment:19
Replying to @jhpalmieri:
This is different from most other things in Sage though. For example
I'm not saying that this is necessarily a bug. However, if you can change |
comment:20
I opened #25935 for |
comment:21
I opened #25940 for |
comment:22
Added one for |
This is potentially a large-scale problem, as can be seen using
TODO LIST (extracted from errors on sage/python3 testsuite):
New failures in 8.4.beta3:
Remains in 8.4.b4:
Remains in 8.4.b5
|| | |
||-----------------------------------------------|----------------------------|
||Bitset objects are unhashable; use FrozenBitset|Not relevant, but see #24852|
|#26313|AffineSpace_generic_with_category||
Remains in 8.4.b7
| | ||
|------|-----------------------------------------------||
|#26419|LabelledBinaryTrees_with_category.element_class||
CC: @jdemeyer @tscrim @kiwifb @embray @vinklein @zerline
Component: python3
Issue created by migration from https://trac.sagemath.org/ticket/24551
The text was updated successfully, but these errors were encountered: