#16250: Monoids._test_one() incorrect for unhashable one elements
-------------------------------------+-------------------------------------
Reporter: saraedum | Owner:
Type: defect | Status: needs_work
Priority: trivial | Milestone: sage-6.3
Component: categories | Resolution:
Keywords: hash | Merged in:
Authors: Julian Rüth | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
u/saraedum/ticket/16250 | c4f8c62f8da90c776a32a86dd768c490fc50836a
Dependencies: | Stopgaps:
-------------------------------------+-------------------------------------
Description changed by saraedum:
Old description:
> In `categories.Monoids._test_one()` the hash value of a monoid's one is
> tested.
> {{{
> tester.assertEqual(type(one.__hash__()), int)
> tester.assertEqual(one.__hash__(), one.__hash__())
> }}}
> For unhashable objects, such as a `p`-adic one this should not be tested.
> It currently works, because `__hash__()` is inherited and therefore
> defined. However, since `p`-adics overwrite `__richcmp__` (in
> `padic_generic_element.pyx`) they are not hashable, i.e., `hash(one)`
> raises a `TypeError`.
>
> The same problem exists for `CommutativeAdditiveMonoids._test_zero()`.
New description:
In `categories.Monoids._test_one()` the hash value of a monoid's one is
tested.
{{{
tester.assertEqual(type(one.__hash__()), int)
tester.assertEqual(one.__hash__(), one.__hash__())
}}}
For unhashable objects, such as a p-adic one this should not be tested. It
currently works, because `__hash__()` is inherited and therefore defined.
Eventually, `__hash__` will be dropped #11598. In this ticket, the
behaviour is changed, so that `_test_one()` does not check the hash if the
element does not inherit from `collections.Hashable`. However, this does
not work for Cython extension classes:
http://permalink.gmane.org/gmane.comp.python.cython.user/11569. For
those, this check has to be skipped explicitly.
The same problem exists for `CommutativeAdditiveMonoids._test_zero()`.
--
--
Ticket URL: <http://trac.sagemath.org/ticket/16250#comment:16>
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.