Issue 36203: PyWeakref_NewRef docs are misleading (original) (raw)

Created on 2019-03-06 01:03 by tekknolagi, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 12244 closed python-dev,2019-03-09 00:04
PR 26273 open tekknolagi,2021-05-20 20:08
Messages (6)
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) * (Python committer) Date: 2021-05-20 18:07
Please add unit tests to the patch.
History
Date User Action Args
2022-04-11 14:59:12 admin set github: 80384
2021-05-20 20:08:43 tekknolagi set pull_requests: + <pull%5Frequest24879>
2021-05-20 18:07:38 iritkatriel set nosy: + iritkatrielmessages: + versions: + Python 3.9, Python 3.10, Python 3.11, - Python 3.6, Python 3.7, Python 3.8
2019-03-09 00:04:19 python-dev set keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest12232>
2019-03-07 08:23:58 tekknolagi set messages: +
2019-03-07 08:20:45 Windson Yang set messages: +
2019-03-06 16:33:19 tekknolagi set messages: +
2019-03-06 11:32:12 Windson Yang set nosy: + Windson Yangmessages: +
2019-03-06 07:38:12 SilentGhost set assignee: docs@pythontype: behaviorcomponents: + Documentation, ctypesnosy: + docs@python
2019-03-06 01:03:50 tekknolagi create