← 输入框|github.com|刷新
Skip to content

Segfault when a functools.partial's keywords are cleared during the call #162774

In progress

Description

@cmaloney

Crash report

from functools import partial

class Key:
    def __call__(self, x):
        p.keywords.clear()
        return x

p = partial(sorted, key=Key())
p([3, 2, 1])

Segfaults on 3.15 and main: list_sort_impl calls the key function after it has been freed. 3.14 returns [1, 2, 3].

The same thing without partial is fine:

class Key:
    def __call__(self, x):
        kw.clear()
        return x

kw = {'key': Key()}
sorted([3, 2, 1], **kw)  # [1, 2, 3]

Related:

CPython versions tested on:

3.15, CPython main branch

Operating systems tested on:

No response

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

No response

Activity

  1. self-assigned this
    on Nov 27, 2026
  2. added
    extension-modules
    type-crash
    3.15
    3.16
    on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.153.16extension-modulestype-crash

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions