Ticket #13801: trac_13801-fix_facade_initialisation-vd.patch

File trac_13801-fix_facade_initialisation-vd.patch, 3.0 KB (added by vdelecroix, 6 years ago)
  • sage/categories/facade_sets.py

    # HG changeset patch
    # User Vincent Delecroix <20100.delecroix at gmail.com>
    # Date 1360966701 18000
    # Node ID 1e9fd320c0318b3e607455ea3f0741d76dd9378f
    # Parent  2491d6e2e9817f73fb0249b887bfd359ae2eb2b2
    trac 13801: fix facade category initialisation
    
    diff --git a/sage/categories/facade_sets.py b/sage/categories/facade_sets.py
    a b  
    9696
    9797    .. note:: the concept of facade parents was originally introduced
    9898       in the computer algebra system MuPAD.
     99
     100    TESTS:
     101
     102    Check that multiple categories initialisation works (:trac:`13801`)::
     103
     104        sage: class A(Parent):
     105        ...     def __init__(self):
     106        ...         Parent.__init__(self, category=(FiniteEnumeratedSets(),Monoids()), facade=True)
     107        sage: a = A()
    99108    """
    100109
    101110    @cached_method
     
    203212
    204213        def facade_for(self):
    205214            """
    206             Returns all the parents this set is a facade for
     215            Returns the parents this set is a facade for
    207216
    208217            This default implementation assumes that ``self`` has
    209218            an attribute ``_facade_for``, typically initialized by
    210             :meth:`Parent.__init__`.
     219            :meth:`Parent.__init__`. If the attribute is not present, the method
     220            raises a NotImplementedError.
    211221
    212222            EXAMPLES::
    213223
     
    215225                An example of facade set: the monoid of positive integers
    216226                sage: S.facade_for()
    217227                (Integer Ring,)
     228
     229            Check that :trac:`13801` is corrected::
     230
     231                sage: class A(Parent):
     232                ...     def __init__(self):
     233                ...         Parent.__init__(self, category=Sets(), facade=True)
     234                sage: a = A()
     235                sage: a.facade_for()
     236                Traceback (most recent call last):
     237                ...
     238                NotImplementedError: this parent did not specify which parents it is a facade for
    218239            """
    219             return self._facade_for
     240            try:
     241                return self._facade_for
     242            except AttributeError:
     243                raise NotImplementedError("this parent did not specify which parents it is a facade for")
    220244
    221245        def is_parent_of(self, element):
    222246            """
  • sage/structure/parent.pyx

    diff --git a/sage/structure/parent.pyx b/sage/structure/parent.pyx
    a b  
    286286            if category is None:
    287287                category = Sets().Facades()
    288288            else:
    289                 category = Category.join((category, Sets().Facades()))
     289                if isinstance(category, (tuple,list)):
     290                    category = Category.join(tuple(category) + (Sets().Facades(),))
     291                else:
     292                    category = Category.join((category,Sets().Facades()))
    290293        # Setting the categories is currently done in a separate
    291294        # method to let some subclasses (like ParentsWithBase)
    292295        # call it without calling the full constructor