python / python/cpython

Use Argument Clinic for more functions and methods

Open
#155,496 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

extension-modules topic-argument-clinic type-refactor
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Many functions and methods implemented in C still parse their arguments with PyArg_ParseTuple() or PyArg_UnpackTuple().
They have no signature for introspection and use the slow METH_VARARGS calling convention.

There are 131 such PyMethodDef entries outside the test modules: _curses 25, _ctypes 16, _interpchannels 13 (GH-139141), time 11, _io 9, _tkinter 8, _thread 6, _csv 5, socket 3, sys 3, and 32 more in 27 files.

A few of them cannot be converted: the behaviour of socket.sendto(), socket.setsockopt() and socket.ioctl() depends on the number or the value of the arguments, and Argument Clinic rejects module-level __getattr__() as a special method.

I am going to submit a separate PR per module.

Linked PRs
  • gh-155511
  • gh-155512
  • gh-155513
  • gh-155514

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the remaining PyMethodDef entries in the listed modules, along with the Argument Clinic conventions already used in CPython. Exclude socket.sendto(), socket.setsockopt(), socket.ioctl(), and module-level getattr(); done means eligible functions and methods use Argument Clinic rather than the stated parsing and calling conventions.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
backend, tooling
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.