This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: weakref.ref ignores a 'callback' keyword argument
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: georg.brandl, mark.dickinson, pitrou, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2013-04-16 19:11 by mark.dickinson, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
no_weakref_kwargs.patch georg.brandl, 2013-10-14 14:43 review
no_weakref_kwargs_2.patch georg.brandl, 2013-10-14 15:37 review
Messages (8)
msg187115 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2013-04-16 19:11
Passing a weakref.ref callback by keyword currently fails silently:

Python 3.4.0a0 (default:537c1f1ab53c, Apr 16 2013, 20:07:47) 
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import weakref
>>> weakref.ref({1, 2, 3}, callback=lambda ref:print("collected"))
<weakref at 0x1006189d8; dead>

For Python 3.4, I'd suggest that either (1) this should be an exception, or (2) it should be permissible to pass the callback by keyword.
msg199898 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2013-10-14 14:43
See attached patch, it handles this like all other builtins that don't support keyword arguments in their constructor.
msg199904 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-10-14 15:07
Why the PyWeakref_Check() in your patch?
msg199909 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2013-10-14 15:35
Good point, that is pointless in __init__().
msg264954 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-05-06 09:40
no_weakref_kwargs_2.patch LGTM.
msg265056 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2016-05-07 09:41
Serhiy, feel free to go ahead and commit, I don't have my keys with me ATM.
msg265062 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-05-07 12:44
New changeset ee17a83feabc by Serhiy Storchaka in branch '3.5':
Issue #17765: weakref.ref() no longer silently ignores keyword arguments.
https://hg.python.org/cpython/rev/ee17a83feabc

New changeset 60de9c6188cc by Serhiy Storchaka in branch '2.7':
Issue #17765: weakref.ref() no longer silently ignores keyword arguments.
https://hg.python.org/cpython/rev/60de9c6188cc

New changeset ef55fa8c4b82 by Serhiy Storchaka in branch 'default':
Issue #17765: weakref.ref() no longer silently ignores keyword arguments.
https://hg.python.org/cpython/rev/ef55fa8c4b82
msg265063 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-05-07 12:47
Done. This issue is similar to recently closed issue26822.

Please give me know if you have other ready to review patches.
History
Date User Action Args
2022-04-11 14:57:44adminsetgithub: 61965
2016-05-07 12:48:00serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg265063

stage: commit review -> resolved
2016-05-07 12:44:33python-devsetnosy: + python-dev
messages: + msg265062
2016-05-07 09:41:05georg.brandlsetmessages: + msg265056
2016-05-07 05:51:24serhiy.storchakasetassignee: georg.brandl
2016-05-06 09:40:28serhiy.storchakasettype: enhancement -> behavior
components: + Extension Modules
versions: + Python 3.5, Python 3.6, - Python 3.3, Python 3.4
nosy: + serhiy.storchaka

messages: + msg264954
stage: needs patch -> commit review
2013-10-14 15:37:24georg.brandlsetfiles: + no_weakref_kwargs_2.patch
2013-10-14 15:35:20georg.brandlsetmessages: + msg199909
2013-10-14 15:07:19pitrousetmessages: + msg199904
2013-10-14 14:43:54georg.brandlsetfiles: + no_weakref_kwargs.patch
versions: + Python 2.7, Python 3.3
nosy: + georg.brandl, pitrou

messages: + msg199898

keywords: + patch
2013-04-16 19:11:10mark.dickinsoncreate