Skip to content

Opt-in macro for a new clean API? Subset of functions with no known issues #54

Description

@vstinner

The Python C API has a long history. Many functions known to be ackwards are kept because of "backward compatibility". The cost of removing them is higher than the benefits.

My use case is: I would like to write a new C extension with only APIs with no known issues. For example, I would like to avoid borrowed references, ambiguous return values, etc.

Can we define a subset of the Python C API for that?

It can be a practical implementation of issue #53: make the C API smaller. Such subset would be smaller by design.

In such subset, we can consider to have different a different deprecation policy: more aggressive. Developers who opt-in for such API are aware of the ongoing effort to fix the C API and so are more eagger to update their code than unmaintained projects which continue to work only because the C API didn't break so far.

In my first C API hack in 2017, I added multiple macros to opt-out from APIs known to have issues. Examples:

  • Py_NEWCAPI: future-proof name, right? :-)
  • Py_NEWCAPI_NO_STRUCT
  • Py_NEWCAPI_NO_MACRO
  • Py_NEWCAPI_BORROWED_REF

I'm not sure if such design is future-proof, C extensions may not be aware that next opt-out options would be added. Maybe it's better to have a single big button: "drop all legacy, give me only good API".

Question: if we design such subset, would it be ok to override names of the regular API? For example, can we rename PyDict_GetItemRef() (regular API) as PyDict_GetItem()? How would it work at the ABI level? Would it be confusing when exchanging code written with the two APIs?

In issue #52, @markshannon proposed using different name prefixes. Rather than using suffixes.

So maybe PyDict_GetItemRef() could become PyNew_Dict_GetItem(), PyNewFinal2CorrectThisThime_Dict_GetItem()? :-)

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions