diff --git a/src/sage/misc/cachefunc.pyx b/src/sage/misc/cachefunc.pyx index 26eef70fa74..77e8691deb0 100644 --- a/src/sage/misc/cachefunc.pyx +++ b/src/sage/misc/cachefunc.pyx @@ -424,6 +424,21 @@ from sage.misc.sageinspect import sage_getfile, sage_getsourcelines, sage_getarg from weakref import WeakValueDictionary +cdef frozenset special_method_names = frozenset(['__abs__', '__add__', + '__and__', '__call__', '__cmp__', '__coerce__', '__complex__', '__contains__', '__del__', + '__delattr__', '__delete__', '__delitem__', '__delslice__', '__dir__', '__div__', + '__eq__', '__float__', '__floordiv__', '__format__', '__ge__', '__get__', '__getattr__', + '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__hex__', + '__iadd__', '__iand__', '__idiv__', '__ifloordiv__', '__ilshift__', '__imod__', '__imul__', + '__index__', '__init__', '__instancecheck__', '__int__', '__invert__', '__ior__', '__ipow__', + '__irshift__', '__isub__', '__iter__', '__itruediv__', '__ixor__', '__le__', '__len__', + '__length_hint__', '__long__', '__lshift__', '__lt__', '__missing__', '__mod__', '__mul__', + '__ne__', '__neg__', '__new__', '__nonzero__', '__oct__', '__or__', '__pos__', '__pow__', + '__radd__', '__rand__', '__rdiv__', '__repr__', '__reversed__', '__rfloordiv__', '__rlshift__', + '__rmod__', '__rmul__', '__ror__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', + '__rtruediv__', '__rxor__', '__set__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', + '__str__', '__sub__', '__subclasscheck__', '__truediv__', '__unicode__', '__xor__', 'next']) + def _cached_function_unpickle(module,name): """ Unpickling of cached functions. @@ -2366,7 +2381,7 @@ def cached_method(f, name=None): """ cdef str fname = name or f.__name__ - if fname.startswith("__") and fname.endswith("__"): + if fname in special_method_names: return CachedSpecialMethod(f, name) return CachedMethod(f, name)