Skip to content

[C API] Add PySys_GetAttr() function #129367

Description

@vstinner

Feature or enhancement

Proposal:

The existing PySys_GetObject() function has two issues:

  • It returns a borrowed reference.
  • It ignores errors.

I propose adding new functions PySys_GetAttr() and PySys_GetAttrString() to get a sys module attribute which return a strong reference and don't ignore errors.

API:

PyObject *PySys_GetAttr(PyObject *name)
PyObject *PySys_GetAttrString(const char *name)
  • Return a new object (strong reference) on success.

  • Set an exception and return NULL on error:

    • Set an AttributeError if the attribute doesn't exist.
    • Set a RuntimeError if the sys module cannot be retrieved.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions