#19016: Better hash for Element
-------------------------+-------------------------------------------------
Reporter: | Owner:
ncohen | Status: needs_work
Type: | Milestone: sage-6.9
defect | Resolution:
Priority: | Merged in:
blocker | Reviewers:
Component: misc | Work issues:
Keywords: | Commit:
Authors: | 754dc5794a1a7004c8844cf7cfb64220957c36a5
Nathann Cohen | Stopgaps:
Report Upstream: N/A |
Branch: |
u/ncohen/19016 |
Dependencies: |
-------------------------+-------------------------------------------------
Comment (by nbruin):
Replying to [comment:38 vdelecroix]:
> Nope. To fix just these `test_zero` and `test_one` one way is to allow
to hash the unit but no other elements...
which makes for horrible code! Are you referring to these lines?
{{{
# Check that zero is immutable by asking its hash:
tester.assertEqual(type(zero.__hash__()), int)
tester.assertEqual(zero.__hash__(), zero.__hash__())
}}}
It's better to implement this by asking `hash(zero)`. The first test is
then not even necessary, because the type will be confirmed in the
protocol. Anyway, I think the check is wrong: objects can be immutable
without being hashable.
I don't think python has a universal way of testing immutability, but I do
think that our element types that can be mutable/immutable have a testing
function for that. So we can check it if available:
{{{
if hasattr(zero,"is_immutable"):
tester.assertEqual(zero.is_immutable(),True)
if hasattr(zero,"is_mutable"):
tester.assertEqual(zero.is_mutable(),False)
}}}
--
Ticket URL: <http://trac.sagemath.org/ticket/19016#comment:39>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.