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 — [C API] Move undocumented private _PyArg C API to pycore_modsupport.h internal C API · Issue #110964 · python/cpython

[C API] Move undocumented private _PyArg C API to pycore_modsupport.h internal C API #110964

New issue
Copy link
New issue
Copy link
Closed
Closed
[C API] Move undocumented private _PyArg C API to pycore_modsupport.h internal C API#110964
Copy link
Labels
topic-C-API

Description

@vstinner
vstinner
opened on Oct 17, 2023
Issue body actions

If a 3rd party C extension uses one of these functions, we should consider adding a clean, documented and tested public function to replace it.

Private functions and structures:

  • _PyArg_BadArgument()
  • _PyArg_CheckPositional()
  • _PyArg_NoKeywords()
  • _PyArg_NoPositional()
  • _PyArg_ParseStack()
  • _PyArg_ParseStackAndKeywords()
  • _PyArg_Parser structure
  • _PyArg_UnpackKeywords()
  • _PyArg_UnpackKeywordsWithVararg()
  • _PyArg_UnpackStack()
  • _Py_ANY_VARARGS()

Linked PRs

  • gh-110964: Remove private _PyArg functions #110966
  • gh-110964: clinic: refactor output_templates() #110982
  • gh-110964: clinic: pass clinic argument to bad_argument() #110984

Activity

Next
  1. vstinner
    added
    topic-C-API
    on Oct 17, 2023
  2. vstinner
    changed the title [-][C API] Move undocumented private _PyArg C API to the pycore_modsupport.h internal C API[/-] [+][C API] Move undocumented private _PyArg C API to pycore_modsupport.h internal C API[/+] on Oct 17, 2023
  3. vstinner
    added 2 commits that reference this issue on Oct 17, 2023

    pythongh-110964: Remove private _PyArg functions

    786da8c

    pythongh-110964: Remove private _PyArg functions

    46a846d
  4. vstinner commented on Oct 17, 2023

    @vstinner
    vstinner
    on Oct 17, 2023
    MemberAuthor
    More actions

    Basically, these functions are only used by Argument Clinic.

    _PyArg_ParseTupleAndKeywordsFast(), _PyArg_ParseStackAndKeywords(), _PyArg_UnpackKeywords() and _PyArg_UnpackKeywordsWithVararg() have a _PyArg_Parser argument which is not really used without using the internal C API anyway. AC generates complex code using internal header files:

    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
    #  include "pycore_gc.h"          // PyGC_Head
    #  include "pycore_runtime.h"     // _Py_ID()
    #endif
    
    (...)
    
        #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
    
        #define NUM_KEYWORDS 1
        static struct {
            PyGC_Head _this_is_not_used;
            PyObject_VAR_HEAD
            PyObject *ob_item[NUM_KEYWORDS];
        } _kwtuple = {
            .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
            .ob_item = { &_Py_ID(loop), },
        };
        #undef NUM_KEYWORDS
        #define KWTUPLE (&_kwtuple.ob_base.ob_base)
    
        #else  // !Py_BUILD_CORE
        #  define KWTUPLE NULL
        #endif  // !Py_BUILD_CORE
    
        static const char * const _keywords[] = {"loop", NULL};
        static _PyArg_Parser _parser = {
            .keywords = _keywords,
            .fname = "Future",
            .kwtuple = KWTUPLE,
        };
        #undef KWTUPLE

    PyGC_Head and _Py_ID() API are part of the internal C API, and _Py_ID() must not be used outside Python code base, since we don't guarantee which identifiers are available or not.

  5. vstinner commented on Oct 17, 2023

    @vstinner
    vstinner
    on Oct 17, 2023
    MemberAuthor
    More actions

    _PyArg_ParseStack(args, nargs, format, ...) is like PyArg_ParseTuple(args, format, ...) but for METH_FASTCALL and METH_VECTORCALL calling convention. We should provide an API like _PyArg_ParseStack() in the public API, but I don't know if this API is good or ,not.

    These helper functions are used by AC. I don't know if it would make sense to make them public or not. They should not be complicated to rewrite if they are no longer usable in the public C API:

    • _PyArg_BadArgument()
    • _PyArg_CheckPositional()
    • _PyArg_NoKeywords()
    • _PyArg_NoPositional()
    • _PyArg_ParseStack()
    • _PyArg_UnpackStack()
  6. vstinner
    added 4 commits that reference this issue on Oct 17, 2023

    gh-110964: Remove private _PyArg functions (#110966)

    be5e8a0

    pythongh-110964: clinic: refactor output_templates()

    3f5b550

    pythongh-110964: clinic: refactor output_templates()

    e6cebdb

    pythongh-110964: clinic: pass clinic argument to bad_argument()

    6a70fcd
  7. encukou commented on Oct 17, 2023

    @encukou
    encukou
    on Oct 17, 2023
    Member
    More actions

    I don't know if this API is good or ,not.

    They're vararg functions that return borrowed references, which makes them C-specific and dependent on CPython implementation details. They're quite handy in C, but IMO they'll need a good deal of design work if we're to expose them properly.

  8. vstinner commented on Oct 17, 2023

    @vstinner
    vstinner
    on Oct 17, 2023
    MemberAuthor
    More actions

    IMO they'll need a good deal of design work if we're to expose them properly.

    Yeah, I agree with you.

  9. vstinner
    added 2 commits that reference this issue on Oct 18, 2023

    pythongh-110964: clinic: pass clinic argument to bad_argument()

    26db3ea

    gh-110964: clinic: refactor output_templates() (#110982)

    0937b11
  10. vstinner
    closed this as completedon Nov 8, 2023
  11. 19 remaining items

  12. pmbarrett314
    added 4 commits that reference this issue on Nov 28, 2024

    Add declarations for private functions from pycore_modsupport

    c45e94c

    Add declarations for private functions from pycore_modsupport

    c1d8aa6

    Add declarations for private functions from pycore_modsupport

    f88b54c

    Add declarations for private functions from pycore_modsupport

    bcfe45e
  13. stephanosio
    added 2 commits that reference this issue on Dec 30, 2024

    Add declarations for private functions from pycore_modsupport

    c46142d

    Add declarations for private functions from pycore_modsupport

    1c21781
  14. rdb commented on Jan 9, 2026

    @rdb
    rdb
    on Jan 9, 2026
    More actions

    @vstinner what's the intended replacement for parsing arguments when using METH_FASTCALL? Fastcall is a public API, are we not supposed to use it after all?

  15. vstinner commented on Jan 14, 2026

    @vstinner
    vstinner
    on Jan 14, 2026
    MemberAuthor
    More actions

    @rdb: Hi. This issue is closed. Would you mind to open a new issue to request a public C API for these functions? Describe your use case and explain why we should make these functions public.

  16. rdb commented on Jan 14, 2026

    @rdb
    rdb
    on Jan 14, 2026
    More actions

    @vstinner yes, I know the issue is closed, but my question is most relevant to this issue.

    I'm not asking you to make the functions public, I'm asking you what the intended replacement is. Before fastcall we had PyArg_ParseTupleAndKeywords for argument parsing. The removed functions were the equivalent for fastcall, and fastcall is a public API. So I want to understand whether the intent was to move people away from fastcall or whether there is a different API.

  17. vstinner commented on Jan 15, 2026

    @vstinner
    vstinner
    on Jan 15, 2026
    MemberAuthor
    More actions

    No, the intent was not to move users away from fastcall/vectorcall. The intent was only to remove private functions in the public C API.

  18. rdb commented on Jan 15, 2026

    @rdb
    rdb
    on Jan 15, 2026
    More actions

    I appreciate you taking the time to respond.

    I will attempt one more time to rephrase my question as concisely as possible. What is the intended mechanism by which METH_FASTCALL methods should parse their (keyword) arguments?

  19. vstinner commented on Jan 15, 2026

    @vstinner
    vstinner
    on Jan 15, 2026
    MemberAuthor
    More actions

    What is the intended mechanism by which METH_FASTCALL methods should parse their (keyword) arguments?

    There is no replacement. If you need a public C API for METH_FASTCALL, please open an issue to request such API.

    Reacted by rdb
  20. vstinner commented on Jan 23, 2026

    @vstinner
    vstinner
    on Jan 23, 2026
    MemberAuthor
    More actions

    @rdb: Can you please open a new issue?

  21. vstinner commented on Mar 10, 2026

    @vstinner
    vstinner
    on Mar 10, 2026
    MemberAuthor
    More actions

    @rdb: Can you please open a new issue?

    The new API was added in issue #144175.

  22. roccolate
    added a commit that references this issue on Aug 2, 2026

    Add declarations for private functions from pycore_modsupport

    2ece804
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.