]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-80384: Check that callback is callable at weak reference creation (GH-151145)
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 10 Jun 2026 10:34:55 +0000 (13:34 +0300)
committerGitHub <noreply@github.com>
Wed, 10 Jun 2026 10:34:55 +0000 (13:34 +0300)
commitca32ebf7933742e3b536cdc0619b0e24cce36065
treec7b13b8de190603af1cabc8c02a4fb9c646eb29d
parent11c93d6df3c8cc6b533da3e85bded37102497ef5
gh-80384: Check that callback is callable at weak reference creation (GH-151145)

* Python functions weakref.ref() and weakref.proxy() now raise TypeError
  if the callback argument is not callable or None.
* C functions PyWeakref_NewRef() and PyWeakref_NewProxy() now raise TypeError
  if the callback argument is not callable, None, or NULL.

Co-authored-by: Maxwell Bernstein <emacs@fb.com>
Doc/c-api/weakref.rst
Doc/library/weakref.rst
Lib/test/test_capi/test_weakref.py
Lib/test/test_traceback.py
Lib/test/test_weakref.py
Misc/NEWS.d/next/C_API/2026-06-09-14-50-35.gh-issue-80384.UEGyvB.rst [new file with mode: 0644]
Misc/NEWS.d/next/Library/2026-06-09-14-49-17.gh-issue-80384.ttRAja.rst [new file with mode: 0644]
Objects/weakrefobject.c