#13589: Controlling C3 to solve once for all the Method Resolution Order issues
for
category classes
----------------------------------------------------------+-----------------
Reporter: nthiery | Owner:
nthiery
Type: defect | Status:
needs_review
Priority: major | Milestone:
sage-5.11
Component: categories | Resolution:
Keywords: method resolution order, C3 | Work issues:
Report Upstream: N/A | Reviewers:
Simon King, Florent Hivert
Authors: Nicolas M. ThiƩry, Simon King | Merged in:
Dependencies: #12894, #12876, #11935, #12895, #10193 | Stopgaps:
----------------------------------------------------------+-----------------
Comment (by SimonKing):
After trivially changing it, building Sage works, but it crashes at
startup with
{{{
/home/simon/SAGE/prerelease/sage-5.11.beta3/local/lib/python2.7/site-
packages/sage/categories/category.pyc in
_all_super_categories(self=Category of category_singleton)
871 Category of rngs,
872 Category of semirings,
873 Category of monoids,
874 Category of semigroups,
875 Category of magmas,
876 Category of commutative additive groups,
877 Category of commutative additive monoids,
878 Category of commutative additive semigroups,
879 Category of additive magmas,
880 Category of sets,
881 Category of sets with partial maps,
882 Category of objects]
883 """
884 (result, bases) =
C3_sorted_merge([cat._all_super_categories
885 for cat in
self._super_categories] +
--> 886
[self._super_categories])
self._super_categories = [Category of rngs, Category of semirings]
887 self._super_categories_for_classes = bases
888 return [self] + result
889
890 @lazy_attribute
891 def _all_super_categories_proper(self):
892 r"""
893 All the proper super categories of this category.
894
895 Since :trac:`11943`, the order of super categories is
896 determined by Python's method resolution order C3
algorithm.
897
898 .. seealso:: :meth:`all_super_categories`
899
900 .. note:: this attribute is likely to eventually become a
tuple.
901
/home/simon/SAGE/prerelease/sage-5.11.beta3/local/lib/python2.7/site-
packages/sage/misc/c3_controlled.so in
sage.misc.c3_controlled.C3_sorted_merge (sage/misc/c3_controlled.c:4377)()
KeyError: Category of sets
}}}
But this can be fixed by using `key=category_sort_key` in C3_sorted_merge.
Hence, with the following diff, Sage starts:
{{{
#!diff
diff --git a/sage/categories/category.py b/sage/categories/category.py
--- a/sage/categories/category.py
+++ b/sage/categories/category.py
@@ -883,7 +883,8 @@
"""
(result, bases) = C3_sorted_merge([cat._all_super_categories
for cat in
self._super_categories] +
- [self._super_categories])
+ [self._super_categories],
+ key = category_sort_key)
self._super_categories_for_classes = bases
return [self] + result
diff --git a/sage/misc/c3_controlled.pyx b/sage/misc/c3_controlled.pyx
--- a/sage/misc/c3_controlled.pyx
+++ b/sage/misc/c3_controlled.pyx
@@ -374,7 +374,7 @@
sage: category_sort_key(Rings()) is Rings()._cmp_key
True
"""
- return C._cmp_key
+ return category._cmp_key
cdef class CmpKey:
r"""
}}}
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13589#comment:74>
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.
For more options, visit https://groups.google.com/groups/opt_out.