python / python/cpython

Argument Clinic: move converters defined in several files to libclinic

オープン
#156,261 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

extension-modules topic-argument-clinic type-refactor
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Several custom converters are defined in more than one C file:

  • pid_t — in posixmodule.c, _posixsubprocess.c and resource.c.
  • Py_off_t — in posixmodule.c and _ssl.c; the Py_off_t type and the converter function are duplicated as well, and _io has yet another copy of the type.
  • HANDLE — in _multiprocessing/multiprocessing.c, overlapped.c, msvcrtmodule.c, _testconsole.c and _winapi.c.
  • DWORD — in overlapped.c, winreg.c and _winapi.c.
  • BOOL — in overlapped.c and _winapi.c.

The copies are not always equivalent: two of the pid_t converters compare the result with -1 instead of (pid_t)-1, and DWORD in _winapi.c uses the format unit "k", which accepts negative values, while in other modules it rejects them.

The registry of converters is global, so the definition in the file which is processed first can be used in other files. The generated code therefore depends on the order of processing — removing the definition of HANDLE from one module silently changes the code generated for others.

Other converters are defined only in posixmodule.c, although the corresponding C functions are already shared, so other modules convert the argument in the "impl" function instead of declaring its type:

  • uid_t and gid_t_Py_Uid_Converter() and _Py_Gid_Converter() are declared in posixmodule.h and are called by hand in pwd.getpwuid(), grp.getgrgid() and _posixsubprocess.fork_exec().

There is no converter for time_t at all: time.gmtime(), time.localtime() and time.ctime() parse their argument with a hand-written helper, and _datetime calls _PyTime_ObjectToTime_t() directly.

I am going to move these converters to Tools/clinic/libclinic/converters.py.

Linked PRs
  • gh-156262
  • gh-156294

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Tools/clinic/libclinic/converters.py から始め、posixmodule.c、_posixsubprocess.c、resource.c、_ssl.c、_io、および issue に記載されている Windows モジュールにある converter の定義と共有宣言を調べます。Argument Clinic がモジュールをどのように処理するかを確認し、生成されたコードを比較します。converter が、受け付ける値や生成される動作を変更せずに一元化されていれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
c, python
領域
build-system, tooling
issue の種類
リファクタリング
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。