msg337255 - (view) |
Author: Maxwell Bernstein (tekknolagi) * |
Date: 2019-03-06 01:03 |
The docs for `PyWeakref_NewRef` state "if callback is not callable, None, or NULL, this will return NULL and raise TypeError". It does not appear as though there is a callable check for the callback. |
|
|
msg337292 - (view) |
Author: Windson Yang (Windson Yang) * |
Date: 2019-03-06 11:32 |
Yes, Maxwell. I guess the docs are misleading, the code locate in https://github.com/python/cpython/blob/master/Objects/weakrefobject.c#L748 if (callback == Py_None) callback = NULL; if (callback == NULL) /* return existing weak reference if it exists */ result = ref; if (result != NULL) Py_INCREF(result); else { ... } However, I'm not sure we should fix the docs or the code here. |
|
|
msg337321 - (view) |
Author: Maxwell Bernstein (tekknolagi) * |
Date: 2019-03-06 16:33 |
NewProxy checks if it's callable, so I suppose the code should be fixed. On Wed, Mar 6, 2019, 03:32 Windson Yang <report@bugs.python.org> wrote: > > Windson Yang <wiwindson@outlook.com> added the comment: > > Yes, Maxwell. I guess the docs are misleading, the code locate in > https://github.com/python/cpython/blob/master/Objects/weakrefobject.c#L748 > > if (callback == Py_None) > callback = NULL; > if (callback == NULL) > /* return existing weak reference if it exists */ > result = ref; > if (result != NULL) > Py_INCREF(result); > else { > ... > } > > However, I'm not sure we should fix the docs or the code here. > > ---------- > nosy: +Windson Yang > > _______________________________________ > Python tracker <report@bugs.python.org> > <https://bugs.python.org/issue36203> > _______________________________________ > |
|
|
msg337371 - (view) |
Author: Windson Yang (Windson Yang) * |
Date: 2019-03-07 08:20 |
It looks to me the fix is easy, we just will return NULL and raise TypeError when the callback is not callable, None, or NULL. I'm not an expert in C, but I would love to create a PR for it if you don't have time. |
|
|
msg337372 - (view) |
Author: Maxwell Bernstein (tekknolagi) * |
Date: 2019-03-07 08:23 |
I can likely do it tomorrow. If not I'll update this. On Thu, Mar 7, 2019, 00:20 Windson Yang <report@bugs.python.org> wrote: > > Windson Yang <wiwindson@outlook.com> added the comment: > > It looks to me the fix is easy, we just will return NULL and raise > TypeError when the callback is not callable, None, or NULL. I'm not an > expert in C, but I would love to create a PR for it if you don't have time. > > ---------- > > _______________________________________ > Python tracker <report@bugs.python.org> > <https://bugs.python.org/issue36203> > _______________________________________ > |
|
|
msg394045 - (view) |
Author: Irit Katriel (iritkatriel) *  |
Date: 2021-05-20 18:07 |
Please add unit tests to the patch. |
|
|