Skip to content

Commit 30d94bb

Browse files
better way to have docstring by returning itself
1 parent 16d726f commit 30d94bb

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

pandas/_libs/properties.pyx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ from cpython cimport (
66
PyDict_Contains, PyDict_GetItem, PyDict_SetItem)
77

88

9-
cdef class cache_readonly(object):
9+
cdef class CachedProperty(object):
1010

1111
cdef readonly:
12-
object func, name, doc, allow_setting
12+
object func, name, __doc__, allow_setting
1313

1414
def __init__(self, func=None, allow_setting=False):
1515
if func is not None:
1616
self.func = func
1717
self.name = func.__name__
18-
self.doc = getattr(func, '__doc__', None)
18+
self.__doc__ = getattr(func, '__doc__', None)
1919
self.allow_setting = allow_setting
2020

2121
def __call__(self, func, doc=None):
2222
self.func = func
2323
self.name = func.__name__
24-
self.doc = getattr(func, '__doc__', None)
24+
self.__doc__ = getattr(func, '__doc__', None)
2525
return self
2626

2727
def __get__(self, obj, typ):
@@ -32,7 +32,7 @@ cdef class cache_readonly(object):
3232
try:
3333
cache = obj._cache = {}
3434
except (AttributeError):
35-
return type('cached', (object, ), {'__doc__': self.doc})
35+
return self
3636

3737
if PyDict_Contains(cache, self.name):
3838
# not necessary to Py_INCREF
@@ -57,6 +57,10 @@ cdef class cache_readonly(object):
5757

5858
PyDict_SetItem(cache, self.name, value)
5959

60+
61+
cache_readonly = CachedProperty
62+
63+
6064
cdef class AxisProperty(object):
6165
cdef:
6266
Py_ssize_t axis

0 commit comments

Comments
 (0)