Opened 10 years ago

Last modified 10 years ago

#13688 closed defect

FiniteEnumeratedSets cardinality override — at Version 3

Reported by: Travis Scrimshaw Owned by: Sage Combinat CC user
Priority: major Milestone: sage-5.8
Component: categories Keywords: finite sets, category, cardinality, days45
Cc: Nicolas M. Thiéry, Andrew Mathas, Sage Combinat CC user Merged in:
Authors: Travis Scrimshaw Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by Travis Scrimshaw)

Right now the category FiniteEnumeratedSets overrides a parent class's cardinality() when creating a list. Below is a minimal example of this behavior:

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

    def cardinality(self, bad_arg):

            sage: P = sage.combinat.category_doctest_fail.TestParent()
            sage: P.cardinality(-1)
            sage: v = P.list(); v
            sage: len(v)
            sage: P.cardinality()
            sage: P.cardinality(-1) # This test breaks
        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.

Change History (3)

comment:1 Changed 10 years ago by Travis Scrimshaw

Description: modified (diff)

Tweaked example to show we don't want to change the semantics of cardinality().

comment:2 Changed 10 years ago by Travis Scrimshaw

Authors: Travis Scrimshaw
Cc: Nicolas M. Thiéry Andrew Mathas Sage Combinat CC user added
Status: newneeds_review

Patch which has _cardinality_from_* take dummy optional args and discard them.

comment:3 Changed 10 years ago by Travis Scrimshaw

Description: modified (diff)
Note: See TracTickets for help on using tickets.