Ticket #12510 (closed enhancement: fixed)
Add consistency tests for __nonzero__ in TestSuite.
|Reported by:||hivert||Owned by:||hivert|
|Cc:||stumpc5, sage-combinat||Work issues:|
|Report Upstream:||N/A||Reviewers:||Nathann Cohen|
|Authors:||Florent Hivert||Merged in:||sage-5.7.beta1|
Description (last modified by hivert) (diff)
With many datastructure for elements, comparison to zero could be faster than comparison of two elements. The pythonic way to do that is to use indirectly e.__nonzero__() for example in if not e: .... However, to be able to use consistently this idiom, we have to make sure that the return value of e == e.parent().zero() agrees with bool(e). The purpose of this patch is to add this tests to the standard test suite and to fixe the Sage library according to this policy.
On the way, I discovered that for a some morphism of modules, pickling can be broken if the zero morphism is asked. I also fixes this issue.