@@ -199,7 +199,7 @@ lru_delete_last(LRU *self)
199
199
return ;
200
200
201
201
if (self -> callback ) {
202
-
202
+
203
203
arglist = Py_BuildValue ("OO" , n -> key , n -> value );
204
204
result = PyObject_CallObject (self -> callback , arglist );
205
205
Py_XDECREF (result );
@@ -265,26 +265,27 @@ lru_subscript(LRU *self, register PyObject *key)
265
265
}
266
266
267
267
static PyObject *
268
- LRU_get (LRU * self , PyObject * args )
268
+ LRU_get (LRU * self , PyObject * args , PyObject * keywds )
269
269
{
270
270
PyObject * key ;
271
- PyObject * instead = NULL ;
271
+ PyObject * default_obj = NULL ;
272
272
PyObject * result ;
273
273
274
- if (!PyArg_ParseTuple (args , "O|O" , & key , & instead ))
274
+ static char * kwlist [] = {"key" , "default" , NULL };
275
+ if (!PyArg_ParseTupleAndKeywords (args , keywds , "O|O" , kwlist , & key , & default_obj ))
275
276
return NULL ;
276
277
277
278
result = lru_subscript (self , key );
278
279
PyErr_Clear (); /* GET_NODE sets an exception on miss. Shut it up. */
279
280
if (result )
280
281
return result ;
281
282
282
- if (!instead ) {
283
+ if (!default_obj ) {
283
284
Py_RETURN_NONE ;
284
285
}
285
286
286
- Py_INCREF (instead );
287
- return instead ;
287
+ Py_INCREF (default_obj );
288
+ return default_obj ;
288
289
}
289
290
290
291
static int
@@ -380,7 +381,7 @@ LRU_update(LRU *self, PyObject *args, PyObject *kwargs)
380
381
lru_ass_sub (self , key , value );
381
382
}
382
383
}
383
-
384
+
384
385
if (kwargs != NULL && PyDict_Check (kwargs )) {
385
386
while (PyDict_Next (kwargs , & pos , & key , & value ))
386
387
lru_ass_sub (self , key , value );
@@ -415,13 +416,14 @@ LRU_setdefault(LRU *self, PyObject *args)
415
416
}
416
417
417
418
static PyObject *
418
- LRU_pop (LRU * self , PyObject * args )
419
+ LRU_pop (LRU * self , PyObject * args , PyObject * keywds )
419
420
{
420
421
PyObject * key ;
421
422
PyObject * default_obj = NULL ;
422
423
PyObject * result ;
423
424
424
- if (!PyArg_ParseTuple (args , "O|O" , & key , & default_obj ))
425
+ static char * kwlist [] = {"key" , "default" , NULL };
426
+ if (!PyArg_ParseTupleAndKeywords (args , keywds , "O|O" , kwlist , & key , & default_obj ))
425
427
return NULL ;
426
428
427
429
/* Trying to access the item by key. */
@@ -620,11 +622,11 @@ static PyMethodDef LRU_methods[] = {
620
622
PyDoc_STR ("L.items() -> list of L's items (key,value) in MRU order" )},
621
623
{"has_key" , (PyCFunction )LRU_contains , METH_VARARGS ,
622
624
PyDoc_STR ("L.has_key(key) -> Check if key is there in L" )},
623
- {"get" , (PyCFunction )LRU_get , METH_VARARGS ,
624
- PyDoc_STR ("L.get(key, instead ) -> If L has key return its value, otherwise instead " )},
625
+ {"get" , (PyCFunction )LRU_get , METH_VARARGS | METH_KEYWORDS ,
626
+ PyDoc_STR ("L.get(key, default=None ) -> If L has key return its value, otherwise default " )},
625
627
{"setdefault" , (PyCFunction )LRU_setdefault , METH_VARARGS ,
626
628
PyDoc_STR ("L.setdefault(key, default=None) -> If L has key return its value, otherwise insert key with a value of default and return default" )},
627
- {"pop" , (PyCFunction )LRU_pop , METH_VARARGS ,
629
+ {"pop" , (PyCFunction )LRU_pop , METH_VARARGS | METH_KEYWORDS ,
628
630
PyDoc_STR ("L.pop(key[, default]) -> If L has key return its value and remove it from L, otherwise return default. If default is not given and key is not in L, a KeyError is raised." )},
629
631
{"popitem" , (PyCFunction )LRU_popitem , METH_VARARGS | METH_KEYWORDS ,
630
632
PyDoc_STR ("L.popitem([least_recent=True]) -> Returns and removes a (key, value) pair. The pair returned is the least-recently used if least_recent is true, or the most-recently used if false." )},
0 commit comments