GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Deprecate PyObject_SetAttr(obj, name, NULL): PyObject_DelAttr(obj, name) must be used instead · Issue #106572 · python/cpython

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

New issue
Copy link
New issue
Copy link
Closed
Closed
Deprecate PyObject_SetAttr(obj, name, NULL): PyObject_DelAttr(obj, name) must be used instead#106572
Copy link
Labels
topic-C-API

Description

@vstinner
vstinner
opened on Jul 9, 2023
Issue body actions

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

  • gh-106572: Deprecate PyObject_SetAttr(v, name, NULL) #106573
  • gh-106572: Convert PyObject_DelAttr() to a function #106611

Activity

  1. vstinner commented on Jul 9, 2023

    @vstinner
    vstinner
    on Jul 9, 2023
    MemberAuthor
    More actions

    python-dev discussion in 2015: https://mail.python.org/archives/list/[email protected]/thread/OSKS23WDHU67NQCANPNSAPHATZ2J3W7T/

  2. vstinner commented on Jul 9, 2023

    @vstinner
    vstinner
    on Jul 9, 2023
    MemberAuthor
    More actions

    I wrote PR #105373 to remove the deprecation in the documentation, but @serhiy-storchaka wrote that the deprecation should stay: #105374 (comment)

    Copy of his message:


    The Gmane link no longer work, the working links to the discussion (it was split on several threads) are
    https://mail.python.org/archives/list/[email protected]/thread/OSKS23WDHU67NQCANPNSAPHATZ2J3W7T/
    https://mail.python.org/archives/list/[email protected]/thread/UJI3KJQVOY7VELTDJOBTBWM3TYDHEYGD/

    The problems with the current behavior:

    1. It looks confusing that some of *Set* functions do removing, while other raise SystemError or crash. Ideally, all such functions should either support deletion by specifying NULL, or raise SystemError. A crash is acceptable too, for performance.
    2. It is a bug magnet. It is easy to get the NULL pointer instead of a pointer to object (just forgot to check for error) and delete instead of set.

    Changing the current behavior is a long process. M.-A. Lemburg specified the required procedure. It is interesting, that if we started it in 3.6, it would already be finished.

  3. vstinner commented on Jul 9, 2023

    @vstinner
    vstinner
    on Jul 9, 2023
    MemberAuthor
    More actions

    I reported this error prone API as capi-workgroup/problems#47

  4. vstinner commented on Jul 9, 2023

    @vstinner
    vstinner
    on Jul 9, 2023
    MemberAuthor
    More actions

    We should consider deprecating similar APIs used to delete an item/attribute:

    • PyObject_SetItem(obj, key, NULL): use PyObject_DelItem(obj, key) instead
    • PyMapping_SetItemString(obj, key, NULL): use PyMapping_DelItemString(obj, key) instead
    • PySequence_SetItem(obj, index, NULL): use PySequence_DelItem(obj, index) instead
    • PySequence_SetSlice(obj, i1, i2, NULL): use PySequence_DelSlice(obj, i1, i2) instead
  5. vstinner
    added 3 commits that reference this issue on Jul 10, 2023

    pythongh-106572: Deprecate PyObject_SetAttr(v, name, NULL)

    d414fec

    pythongh-106572: Deprecate PyObject_SetAttr(v, name, NULL)

    1ee5f8c

    pythongh-106572: Deprecate PyObject_SetAttr(v, name, NULL)

    83ac93f
  6. serhiy-storchaka commented on Jul 10, 2023

    @serhiy-storchaka
    serhiy-storchaka
    on Jul 10, 2023
    Member
    More actions

    Unfortunately, adding a warning will break binary compatibility. Code compiled with older Python version which uses PyObject_DelAttr() calls PyObject_SetAttr(), because PyObject_DelAttr() was implemented as a macro.

    We should first implement PyObject_DelAttr() as a separate function, then in some distant future we decide to break binary compatibility with Python older than 3.13 and add a warning, then error, in PyObject_SetAttr().

  7. vstinner
    added 7 commits that reference this issue on Jul 10, 2023

    pythongh-106572: Implement PyObject_DelAttr() as a function

    a7200a0

    pythongh-106572: Convert PyObject_DelAttr() to a function

    e85cb7c

    pythongh-106572: Convert PyObject_DelAttr() to a function

    aae498b

    gh-106572: Convert PyObject_DelAttr() to a function (#106611)

    1f2921b

    pythongh-106572: Deprecate PyObject_SetAttr(v, name, NULL)

    1f5bbc2

    pythongh-106572: Deprecate PyObject_SetAttr(v, name, NULL)

    936bd14

    pythongh-106572: Deprecate PyObject_SetAttr(v, name, NULL)

    e6956af
  8. vstinner
    added
    topic-C-API
    on Jul 13, 2023
  9. vstinner commented on Jul 25, 2023

    @vstinner
    vstinner
    on Jul 25, 2023
    MemberAuthor
    More actions

    I close the issue: see #106573 (comment)

  10. vstinner
    closed this as completedon Jul 25, 2023
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

    topic-C-API

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.