#13688: FiniteEnumeratedSets cardinality override
------------------------------------------------------+---------------------
       Reporter:  tscrim                              |         Owner:  
sage-combinat
           Type:  defect                              |        Status:  
needs_review 
       Priority:  major                               |     Milestone:  
sage-5.7     
      Component:  categories                          |    Resolution:          
     
       Keywords:  finite sets, category, cardinality  |   Work issues:          
     
Report Upstream:  N/A                                 |     Reviewers:          
     
        Authors:  Travis Scrimshaw                    |     Merged in:          
     
   Dependencies:                                      |      Stopgaps:          
     
------------------------------------------------------+---------------------
Description changed by tscrim:

Old description:

> Right now the category `FiniteEnumeratedSets` overrides a parent class's
> `cardinality()` when creating a list. Below is a minimal example of this
> behavior:
> {{{#!python
> from sage.structure.parent import Parent
> from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
>
> class TestParent(Parent):
>     def __init__(self):
>         Parent.__init__(self, category=FiniteEnumeratedSets())
>
>     def __iter__(self):
>         yield 1
>         return
>
>     def cardinality(self, bad_arg):
>         """
>         EXAMPLES::
>
>             sage: P = sage.combinat.category_doctest_fail.TestParent()
>             sage: P.cardinality(-1)
>             1
>             sage: v = P.list(); v
>             [1]
>             sage: len(v)
>             1
>             sage: P.cardinality()
>             1
>             sage: P.cardinality(-1) # This test breaks
>             1
>         """
>         return 1 # we don't want to change the semantics of cardinality()
> }}}
>
> This seems to be caused by not checking if the parent class has a
> `cardinality()` function implemented, and just overriding it with
> `_cardinality_from_list()` (which takes no [optional] parameters).

New description:

 Right now the category `FiniteEnumeratedSets` overrides a parent class's
 `cardinality()` when creating a list. Below is a minimal example of this
 behavior:
 {{{#!python
 from sage.structure.parent import Parent
 from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets

 class TestParent(Parent):
     def __init__(self):
         Parent.__init__(self, category=FiniteEnumeratedSets())

     def __iter__(self):
         yield 1
         return

     def cardinality(self, bad_arg):
         """
         EXAMPLES::

             sage: P = sage.combinat.category_doctest_fail.TestParent()
             sage: P.cardinality(-1)
             1
             sage: v = P.list(); v
             [1]
             sage: len(v)
             1
             sage: P.cardinality()
             1
             sage: P.cardinality(-1) # This test breaks
             1
         """
         return 1 # we don't want to change the semantics of cardinality()
 }}}

 This seems to be caused by not checking if the parent class has a
 `cardinality()` function implemented, and just overriding it with
 `_cardinality_from_list()` (which takes no [optional] parameters).

 NOTE: The failure will '''only''' show up while running doctests using
 `sage -t`, not while running sage.

--

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13688#comment:3>
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to