Changes between Version 3 and Version 4 of Ticket #14065


Ignore:
Timestamp:
02/11/13 16:28:33 (8 years ago)
Author:
tscrim
Comment:

Added additional doctests about the MRO.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #14065 – Description

    v3 v4  
    22
    33Another issue this ticket does is add a `__nonzero__()` to `CombinatorialObject` so things like `if p:` and `not p` will work when also inheriting from `Element` (which checks against the `Parent().zero_element()` and is not implemented for all parents).
     4
     5Here's an example of how this breaks:
     6{{{
     7sage: from sage.structure.element import Element
     8sage: class Foo(CombinatorialObject, Element):
     9...       def __init__(self, l):
     10...           CombinatorialObject.__init__(self, l)
     11...
     12sage: L = [Foo([4-i]) for i in range(4)]
     13sage: sorted(L, cmp)
     14Traceback (most recent call last):
     15...
     16NotImplementedError: BUG: sort algorithm for elements of 'None' not implemented
     17
     18sage: f = Foo([4])
     19sage: not f
     20Traceback (most recent call last):
     21...
     22AttributeError: 'NoneType' object has no attribute 'zero_element'
     23}}}
     24
     25'''NOTE''' - After the patch, the `CombinatorialObject` needs to come ''before'' `Element` because of the MRO.