Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FiniteEnumeratedSets cardinality override #13688

Closed
tscrim opened this issue Nov 5, 2012 · 12 comments
Closed

FiniteEnumeratedSets cardinality override #13688

tscrim opened this issue Nov 5, 2012 · 12 comments

Comments

@tscrim
Copy link
Collaborator

tscrim commented Nov 5, 2012

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
        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/keyword] parameters).

CC: @nthiery @AndrewAtLarge @sagetrac-sage-combinat

Component: categories

Keywords: finite sets, cardinality, days45

Author: Travis Scrimshaw

Reviewer: Andrew Mathas

Merged: sage-5.8.beta1

Issue created by migration from https://trac.sagemath.org/ticket/13688

@tscrim

This comment has been minimized.

@tscrim
Copy link
Collaborator Author

tscrim commented Nov 6, 2012

comment:1

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

@tscrim
Copy link
Collaborator Author

tscrim commented Feb 16, 2013

Author: Travis Scrimshaw

@tscrim
Copy link
Collaborator Author

tscrim commented Feb 16, 2013

comment:2

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

@tscrim

This comment has been minimized.

@AndrewMathas
Copy link
Member

Changed keywords from finite sets, cardinality to finite sets, cardinality, days45

@AndrewMathas
Copy link
Member

Reviewer: Andrew Mathas

@AndrewMathas
Copy link
Member

comment:4

The patch is quite innocuous and fixes a problem. All doc tests pass.

Can you add a doctest for testing for this? Presumably it showed up in a real class. Happy for you to set this to a positive review once that's done.

@tscrim
Copy link
Collaborator Author

tscrim commented Feb 20, 2013

comment:5

Replying to @AndrewAtLarge:

Can you add a doctest for testing for this?

Done. I expanded on the example I gave in the description.

Presumably it showed up in a real class.

In partition.py after #13605 is applied (of course without this patch).

Happy for you to set this to a positive review once that's done.

Also done. Thank you for reviewing this.

Best,

Travis

@tscrim

This comment has been minimized.

@jdemeyer
Copy link

Merged: sage-5.8.beta1

@jdemeyer
Copy link

comment:6

Attachment: trac_13688-finite_sets_cardinality_override-ts.patch.gz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants