mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
ensure .keywords is always a dict
This commit is contained in:
parent
07abcf58d9
commit
65bcdd7195
3 changed files with 9 additions and 9 deletions
|
@ -77,9 +77,11 @@ class TestPartial:
|
||||||
# exercise special code paths for no keyword args in
|
# exercise special code paths for no keyword args in
|
||||||
# either the partial object or the caller
|
# either the partial object or the caller
|
||||||
p = self.partial(capture)
|
p = self.partial(capture)
|
||||||
|
self.assertEqual(p.keywords, {})
|
||||||
self.assertEqual(p(), ((), {}))
|
self.assertEqual(p(), ((), {}))
|
||||||
self.assertEqual(p(a=1), ((), {'a':1}))
|
self.assertEqual(p(a=1), ((), {'a':1}))
|
||||||
p = self.partial(capture, a=1)
|
p = self.partial(capture, a=1)
|
||||||
|
self.assertEqual(p.keywords, {'a':1})
|
||||||
self.assertEqual(p(), ((), {'a':1}))
|
self.assertEqual(p(), ((), {'a':1}))
|
||||||
self.assertEqual(p(b=2), ((), {'a':1, 'b':2}))
|
self.assertEqual(p(b=2), ((), {'a':1, 'b':2}))
|
||||||
# keyword args in the call override those in the partial object
|
# keyword args in the call override those in the partial object
|
||||||
|
|
|
@ -57,6 +57,8 @@ Library
|
||||||
- Issue #9246: On POSIX, os.getcwd() now supports paths longer than 1025 bytes.
|
- Issue #9246: On POSIX, os.getcwd() now supports paths longer than 1025 bytes.
|
||||||
Patch written by William Orr.
|
Patch written by William Orr.
|
||||||
|
|
||||||
|
- The keywords attribute of functools.partial is now always a dictionary.
|
||||||
|
|
||||||
- Issues #24099, #24100, and #24101: Fix free-after-use bug in heapq's siftup
|
- Issues #24099, #24100, and #24101: Fix free-after-use bug in heapq's siftup
|
||||||
and siftdown functions.
|
and siftdown functions.
|
||||||
|
|
||||||
|
|
|
@ -54,17 +54,13 @@ partial_new(PyTypeObject *type, PyObject *args, PyObject *kw)
|
||||||
Py_DECREF(pto);
|
Py_DECREF(pto);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (kw != NULL) {
|
pto->kw = (kw != NULL) ? PyDict_Copy(kw) : PyDict_New();
|
||||||
pto->kw = PyDict_Copy(kw);
|
if (pto->kw == NULL) {
|
||||||
if (pto->kw == NULL) {
|
Py_DECREF(pto);
|
||||||
Py_DECREF(pto);
|
return NULL;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
pto->kw = Py_None;
|
|
||||||
Py_INCREF(Py_None);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pto->weakreflist = NULL;
|
pto->weakreflist = NULL;
|
||||||
pto->dict = NULL;
|
pto->dict = NULL;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue