Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10299,6 +10299,17 @@ def test_args_kwargs(self):
self.assertEqual(repr(P.args), "P.args")
self.assertEqual(repr(P.kwargs), "P.kwargs")

def test_args_kwargs_weakrefs(self):
P = ParamSpec('P')
for attr_name in ('args', 'kwargs'):
with self.subTest(attr_name=attr_name):
callback_fired = []
attr = getattr(P, attr_name)
ref = weakref.ref(attr, lambda _: callback_fired.append(True))
del attr
self.assertEqual(callback_fired, [True])
self.assertIsNone(ref())

def test_stringized(self):
P = ParamSpec('P')
class C(Generic[P]):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a crash when a weak-reference callback is attached to a
:class:`typing.ParamSpecArgs` or :class:`typing.ParamSpecKwargs` instance.
1 change: 1 addition & 0 deletions Objects/typevarobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ paramspecattr_dealloc(PyObject *self)
_PyObject_GC_UNTRACK(self);

Py_XDECREF(psa->__origin__);
PyObject_ClearWeakRefs(self);

Py_TYPE(self)->tp_free(self);
Py_DECREF(tp);
Expand Down
Loading