Ticket #13400: trac_13400_subclass_hook_cython.patch

File trac_13400_subclass_hook_cython.patch, 2.2 KB (added by SimonKing, 7 years ago)

Cythonise _subcategory_hook_. Experimental, and a bit off-topic

  • module_list.py

    # HG changeset patch
    # User Simon King <simon.king@uni-jena.de>
    # Date 1345921193 -7200
    # Node ID 150be340e81d4f5a68a1701b0ed8b0c7ea1dd422
    # Parent  7676500895349a7a7981caa440ff395ebacddcac
    imported patch trac_13400_subclass_hook_cython.patch
    
    diff --git a/module_list.py b/module_list.py
    a b  
    151151    Extension('sage.categories.category_singleton',
    152152              sources = ['sage/categories/category_singleton.pyx']),
    153153
     154    Extension('sage.categories.auxiliary_methods',
     155              sources = ['sage/categories/auxiliary_methods.pyx']),
     156
    154157    Extension('sage.categories.functor',
    155158              sources = ['sage/categories/functor.pyx']),
    156159             
  • new file sage/categories/auxiliary_methods.pyx

    diff --git a/sage/categories/auxiliary_methods.pyx b/sage/categories/auxiliary_methods.pyx
    new file mode 100644
    - +  
     1include "../ext/python_type.pxi"
     2cdef class subcategory_hook:
     3    cdef object parent_class
     4    def __init__(self,c):
     5        self.parent_class = c.parent_class
     6    def __call__(self,c):
     7        return PyType_IsSubtype(c.parent_class, self.parent_class)
  • sage/categories/category.py

    diff --git a/sage/categories/category.py b/sage/categories/category.py
    a b  
    106106from sage.structure.unique_representation import UniqueRepresentation
    107107from sage.structure.dynamic_class import dynamic_class_internal
    108108
     109from sage.categories.auxiliary_methods import subcategory_hook
     110
    109111from weakref import WeakValueDictionary
    110112_join_cache = WeakValueDictionary()
    111113
     
    619621#         """
    620622#         return hash(self.__category) # Any reason not to use id?
    621623
    622     def _subcategory_hook_(self, category):
     624    @lazy_attribute
     625    def _subcategory_hook_(self):#, category):
    623626        """
    624627        Quick subcategory check.
    625628
     
    655658            sage: Rings()._subcategory_hook_(Rings())
    656659            True
    657660        """
    658         return issubclass(category.parent_class, self.parent_class)
     661        return subcategory_hook(self)
     662        #return issubclass(category.parent_class, self.parent_class)
    659663
    660664    def __contains__(self, x):
    661665        """