@@ -15,6 +15,7 @@ limitations under the License.
1515*/
1616
1717#include "core.h"
18+ #include "pydoc.h"
1819
1920#include <Python.h>
2021#include <time.h>
@@ -690,11 +691,11 @@ static PyMethodDef CacheMap_methods[] = {
690691 {"set_capacity" , (PyCFunction )CacheMap_set_capacity , METH_O ,
691692 "set_capacity(capacity, /)\n--\n\n Reset capacity of cache." },
692693 {"hit_info" , (PyCFunction )CacheMap_hit_info , METH_NOARGS ,
693- "Return capacity, hits, and misses count" },
694+ "hit_info()\n--\n\nReturn capacity, hits, and misses count. " },
694695 {"next_evict_key" , (PyCFunction )CacheMap_NextEvictKey , METH_NOARGS ,
695- "Return the most unused key." },
696+ "next_evict_key()\n--\n\nReturn the most unused key." },
696697 {"get" , (PyCFunction )CacheMap_get , METH_VARARGS | METH_KEYWORDS ,
697- "get(key, default=None)\n--\n\nGet item from cache" },
698+ "get(key, default=None)\n--\n\nGet item from cache. " },
698699 {"setdefault" , (PyCFunction )CacheMap_setdefault ,
699700 METH_VARARGS | METH_KEYWORDS ,
700701 "setdefault(key, default=None, /)\n--\n\nGet item in cache, if key not "
@@ -703,19 +704,29 @@ static PyMethodDef CacheMap_methods[] = {
703704 "pop(key, default=None, /)\n--\n\nPop an item from cache, if key not "
704705 "exists return default." },
705706 {"popitem" , (PyCFunction )CacheMap_popitem , METH_NOARGS ,
706- "popitem()\n--\n\nremove and return some (key, value) pair"
707- "as a 2-tuple; but raise KeyError if mapping is empty" },
708- {"keys" , (PyCFunction )CacheMap_keys , METH_NOARGS , "Iter keys." },
709- {"values" , (PyCFunction )CacheMap_values , METH_NOARGS , "Iter values." },
707+ "popitem()\n--\n\nRemove and return some (key, value) pair"
708+ "as a 2-tuple; but raise KeyError if mapping is empty." },
709+ {"keys" , (PyCFunction )CacheMap_keys , METH_NOARGS ,
710+ "keys()\n--\n\nIter keys." },
711+ {"values" , (PyCFunction )CacheMap_values , METH_NOARGS ,
712+ "values()\n--\n\nIter values." },
710713 {"items" , (PyCFunction )CacheMap_items , METH_NOARGS ,
711- "Iter keys and values." },
714+ "items()\n--\n\nIter keys and values." },
712715 {"update" , (PyCFunction )CacheMap_update , METH_VARARGS | METH_KEYWORDS ,
713716 "update(map, /)\n--\n\nUpdate item to cache. Unlike dict.update, only "
714717 "accept a dict object." },
715- {"clear" , (PyCFunction )CacheMap_clear , METH_NOARGS , "clean cache" },
716- {"setnx" , (PyCFunction )CacheMap_setnx , METH_VARARGS | METH_KEYWORDS ,
717- "setnx(key, fn, /)\n--\n\nLike setdefault but accept a callable "
718- "object which takes key as only one argument" },
718+ {
719+ "clear" ,
720+ (PyCFunction )CacheMap_clear ,
721+ METH_NOARGS ,
722+ "clear()\n--\n\nClean cache." ,
723+ },
724+ {
725+ "setnx" ,
726+ (PyCFunction )CacheMap_setnx ,
727+ METH_VARARGS | METH_KEYWORDS ,
728+ USUAL_SETNX_METHOD_DOC ,
729+ },
719730 {"_storage" , (PyCFunction )CacheMap__storage , METH_NOARGS , NULL },
720731 {NULL , NULL , 0 , NULL } /* Sentinel */
721732};
@@ -743,19 +754,25 @@ static PyObject *CacheMap_tp_richcompare(PyObject *self, PyObject *other,
743754 }
744755}
745756
746- PyDoc_STRVAR (CacheMap__doc__ , "CacheMap(maxsize=None, /)\n\n"
747- "A fast LFU (least frequently used) mapping.\n\n"
748- "Default max size is C ``INT32_MAX``.\n\n"
749- "Examples\n"
750- "--------\n"
751- ">>> import ctools\n"
752- ">>> cache = ctools.CacheMap(1)\n"
753- ">>> cache['foo'] = 'bar'\n"
754- ">>> cache['foo']\n"
755- "'bar'\n"
756- ">>> cache['bar'] = 'foo'\n"
757- ">>> 'foo' in cache\n"
758- "False\n" );
757+ PyDoc_STRVAR (CacheMap__doc__ ,
758+ "CacheMap(maxsize=None, )\n--\n\n"
759+ "A fast LFU (least frequently used) mapping.\n"
760+ "\n"
761+ "Parameters\n"
762+ "----------\n"
763+ "maxsize : int\n"
764+ " Max size of cache, default is C ``INT32_MAX``.\n"
765+ "\n"
766+ "Examples\n"
767+ "--------\n"
768+ ">>> import ctools\n"
769+ ">>> cache = ctools.CacheMap(1)\n"
770+ ">>> cache['foo'] = 'bar'\n"
771+ ">>> cache['foo']\n"
772+ "'bar'\n"
773+ ">>> cache['bar'] = 'foo'\n"
774+ ">>> 'foo' in cache\n"
775+ "False\n" );
759776
760777static PyTypeObject CacheMap_Type = {
761778 /* clang-format off */
0 commit comments