Skip to content

Commit

Permalink
avoid naming cython attributes __module__
Browse files Browse the repository at this point in the history
  • Loading branch information
infmagic2047 committed Aug 18, 2023
1 parent 89d83ff commit 1809b48
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/sage/misc/cachefunc.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cpdef cache_key(o)

cdef class CachedFunction():
cdef public str __name__
cdef public str __module__
cdef public str __cached_module__
cdef ArgumentFixer _argument_fixer
cdef public f
cdef public cache # not always of type <dict>
Expand All @@ -20,7 +20,7 @@ cdef class CachedFunction():
cdef class CachedMethod():
cdef str _cache_name
cdef public str __name__
cdef public str __module__
cdef public str __cached_module__
cdef CachedFunction _cachedfunc
cdef Py_ssize_t nargs
cpdef _get_instance_cache(self, inst)
Expand Down
16 changes: 12 additions & 4 deletions src/sage/misc/cachefunc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -761,13 +761,17 @@ cdef class CachedFunction():
else:
self.__name__ = f.__name__
try:
self.__module__ = f.__module__
self.__cached_module__ = f.__module__
except AttributeError:
self.__module__ = f.__objclass__.__module__
self.__cached_module__ = f.__objclass__.__module__
if argument_fixer is not None: # it is None unless the argument fixer
# was known previously. See #15038.
self._argument_fixer = argument_fixer

@property
def __module__(self):
return self.__cached_module__

cdef get_key_args_kwds(self, tuple args, dict kwds):
"""
Return the key in the cache to be used when ``args`` and
Expand Down Expand Up @@ -828,7 +832,7 @@ cdef class CachedFunction():
sage: loads(dumps(hilbert_class_polynomial)) is hilbert_class_polynomial #indirect doctest
True
"""
return _cached_function_unpickle, (self.__module__, self.__name__, self.cache)
return _cached_function_unpickle, (self.__cached_module__, self.__name__, self.cache)

#########
## Introspection
Expand Down Expand Up @@ -2675,7 +2679,11 @@ cdef class CachedMethod():
self._cache_name = '_cache__' + (name or f.__name__)
self._cachedfunc = CachedFunction(f, classmethod=True, name=name, key=key, do_pickle=do_pickle)
self.__name__ = self._cachedfunc.__name__
self.__module__ = self._cachedfunc.__module__
self.__cached_module__ = self._cachedfunc.__module__

@property
def __module__(self):
return self.__cached_module__

def __call__(self, inst, *args, **kwds):
"""
Expand Down

0 comments on commit 1809b48

Please sign in to comment.