Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-106320: Remove private _PyDict C API #107145

Merged
merged 1 commit into from Jul 24, 2023
Merged

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Jul 23, 2023

Move private _PyDict functions to the internal C API (pycore_dict.h):

  • _PyDict_Contains_KnownHash()
  • _PyDict_DebugMallocStats()
  • _PyDict_DelItemIf()
  • _PyDict_GetItemWithError()
  • _PyDict_HasOnlyStringKeys()
  • _PyDict_MaybeUntrack()
  • _PyDict_MergeEx()

No longer export these functions.

@vstinner
Copy link
Member Author

For now, I kept _PyDict_GetItemStringWithError() since it's used by _testcapi. The new public PyDict_GetItemStringRef() can be used by _testcapi instead.

@vstinner
Copy link
Member Author

@methane: Do you want to prefer to keep a few of these private _PyDict functions for now? Or is it ok to remove them right now from the C API?

If one of these private functions make sense outside CPython code base, we should consider making it public: see https://discuss.python.org/t/c-api-my-plan-to-clarify-private-vs-public-functions-in-python-3-13/30131

@vstinner
Copy link
Member Author

With this PR, there are still the following private _PyDict functions:

  • _PyDictView_Intersect()
  • _PyDictView_New()
  • _PyDict_ContainsId()
  • _PyDict_DelItemId()
  • _PyDict_GetItemIdWithError()
  • _PyDict_GetItemStringWithError()
  • _PyDict_Next()
  • _PyDict_Pop()
  • _PyDict_SetItemId()
  • _PyDict_SizeOf()

I consider removing them later, except of the "Id" variants.

@methane
Copy link
Member

methane commented Jul 24, 2023

Cython uses _PyDict_GetItem_KnownHash and _PyDict_NewPresized().
So removing them will break some packages.
I don't know other private API users.

@vstinner
Copy link
Member Author

The main branch of Cython uses the following private _PyDict functions:

  • _PyDict_GetItem_KnownHash()
  • _PyDict_NewPresized()
  • _PyDict_Pop()
  • _PyDict_SetItem_KnownHash()

Ok, let's keep these one for them, until we decide if we should make them public, or if Cython should avoid them.

Move private _PyDict functions to the internal C API (pycore_dict.h):

* _PyDict_Contains_KnownHash()
* _PyDict_DebugMallocStats()
* _PyDict_DelItemIf()
* _PyDict_GetItemWithError()
* _PyDict_HasOnlyStringKeys()
* _PyDict_MaybeUntrack()
* _PyDict_MergeEx()

No longer export these functions.
@vstinner
Copy link
Member Author

I updated my PR to keep the following functions:

  • _PyDict_DelItem_KnownHash()
  • _PyDict_GetItem_KnownHash()
  • _PyDict_NewPresized()
  • _PyDict_SetItem_KnownHash()

I also rebased it on the main branch.

@vstinner vstinner enabled auto-merge (squash) July 24, 2023 13:40
@vstinner vstinner merged commit fd66baf into python:main Jul 24, 2023
21 of 22 checks passed
carljm added a commit to carljm/cpython that referenced this pull request Jul 24, 2023
* main: (73 commits)
  Thoroughly refactor the cases generator (python#107151)
  Docs: Add missing markup to Argument Clinic docs (python#106876)
  pythongh-107162: Document errcode.h usage in its comment (python#107177)
  pythongh-106320: Remove private _PyDict C API (python#107145)
  Fix PyVectorcall_Function doc versionadded (python#107140)
  Docs: Remove duplicate word in Argument Clinic howto heading (python#107169)
  pythongh-107017: Change Chapter Strings to Texts in the Introduction chapter. (python#107104)
  pythongh-106320: Remove private _PyObject C API (python#107159)
  Docs: fix typo in os.pwrite docstring (python#107087)
  pythongh-105291: Add link to migration guide for distutils (python#107130)
  pythongh-106948: Docs: Disable links for C standard library functions, OS utility functions and system calls (python#107062)
  pythongh-106320: Remove _PyBytes_Join() C API (python#107144)
  pythongh-106320: Remove private _PyObject C API (python#107147)
  pythongh-106320: Remove _PyTuple_MaybeUntrack() C API (python#107143)
  pythongh-106320: Remove _PyIsSelectable_fd() C API (python#107142)
  Remove superflous whitespaces in `layout.html`. (pythonGH-107067)
  pythongh-107122: Update what's news for dbm.*dbm.clear() method (pythongh-107135)
  pythongh-107122: Add clear method to dbm.ndbm module (pythongh-107126)
  pythongh-62519: Make pgettext search plurals when translation is not found (python#107118)
  pythongh-107122: Add clear method to dbm.gdbm.module (pythongh-107127)
  ...
@vstinner vstinner deleted the pycore_dict branch September 13, 2023 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants