Skip to content

Deprecate PyObject_SetAttr(obj, name, NULL): PyObject_DelAttr(obj, name) must be used instead #106572

Closed
@vstinner

Description

@vstinner

When PyObject_SetAttr() is called with a NULL value, it's unclear if the caller wants to remove the attribute on purpose, or if the value is NULL because of an error. Such API is error prone and should be avoided.

In 2005, this feature was already deprecated in the documentation in issue #69887 by commit 45be8d6.

I propose to now emit a DeprecationWarning and schedule the removal of this feature in Python 3.15. If too many C extensions rely on this current behavior, we can consider removing the feature later.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions