Skip to content

Add PyDict_SetDefaultRef() to the stable ABI #85

@da-woods

Description

@da-woods

I'm finding it increasingly useful for certain types of lazy initialization in a freethreaded world. Illustrative example:

# Python illustration for simplicity
some_useful_thing = some_dict.get("key", None)
if some_useful_thing is None:
    some_useful_thing = slightly_expensive_construction()
    some_useful_thing = some_dict.setdefault("key", some_useful_thing)

Essentially for problems where you'd rather do slightly_expensive_construction once (but if you accidentally end up doing it twice then it doesn't really matter). But the most important thing is that everyone uses the same cached attribute at the end of the process.

Obviously it's possible to access it through a Python function call in the current Stable ABI, but more direct access would be nice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions