Skip to content

Crash in clear_weakref() for ParamSpecArgs/ParamSpecKwargs #157621

Description

@stratakis

Crash report

What happened?

gh-108517 (fix for gh-108295) added PyObject_ClearWeakRefs() to typevar_dealloc, paramspec_dealloc, and typevartuple_dealloc, but missed paramspecattr_dealloc(). Both paramspecargs_spec and paramspeckwargs_spec set Py_TPFLAGS_MANAGED_WEAKREF, so the same crash from gh-108295 still occurs for ParamSpec(...).args and ParamSpec(...).kwargs.

  import weakref
  from typing import ParamSpec, TypeVar

  def probe(label, make):
      obj = make()
      fired = []
      r = weakref.ref(obj, lambda ref: fired.append(True))
      del obj
      print(f"  {label:16s} callback_fired={bool(fired)!s:5s}")
      del r

  probe("TypeVar",       lambda: TypeVar("T"))         # Works fine
  probe("ParamSpecArgs", lambda: ParamSpec("P").args)   # segfault

CPython versions tested on:

3.12, 3.13, 3.14, 3.15, 3.16, CPython main branch

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

No response

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-typingtype-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions