Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Faster and more thorough detection of special method names
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-king-jena committed Oct 15, 2013
1 parent fe1e739 commit 6cf1fad
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/sage/misc/cachefunc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 6cf1fad

Please sign in to comment.