Argument Clinic: add a parametrized converter for durations and timestamps
@serhiy-storchaka がすでに取り組んでいます。
2026年8月23日 から。
評価
この issue はまだ評価されていません。
説明
Feature or enhancement
Many functions accept a duration (a timeout, an interval, a delay) or a timestamp, and every one of them converts the argument in the "impl" function. They are declared as object (or double, or a Windows DWORD) and converted with _PyTime_FromSecondsObject(), _PyTime_FromMillisecondsObject(), _PyTime_ObjectToTime_t(), _PyTime_ObjectToTimeval(), _PyTime_ObjectToTimespec() and the corresponding _PyTime_As*() functions.
The conversions differ in several independent aspects:
- the unit of the argument: seconds (most of them) or milliseconds (
select.poll.poll(),select.devpoll.poll()); - the rounding mode:
_PyTime_ROUND_TIMEOUT(select,socket,_thread,faulthandler,time.sleep()),_PyTime_ROUND_CEILING(signal.sigtimedwait(),signal.setitimer(),_queue,_ssl) or_PyTime_ROUND_FLOOR(time.gmtime(),datetime.date.fromtimestamp()); - the type and unit used by the implementation:
PyTime_t(nanoseconds), microseconds or milliseconds as an integer,struct timevalorstruct timespec,doubleseconds,time_tseconds, or WindowsDWORDmilliseconds; - the meaning of
None: block forever (select,_queue,_multiprocessing.SemLock), the current time (time.gmtime(),time.localtime(),time.ctime()), not specified (_thread, where the Python default is-1), or not accepted at all (signal.sigtimedwait()); - the range check: no check, or
ValueErrorwith one of several messages -- "timeout must be non-negative", "timeout must be positive or None", "timeout is too large", "timeout value is too large", "timeout must be greater than 0".
The error for a wrong type differs too: select raises "timeout must be a real number or None, not %T", other modules use the message produced by _PyTime_FromSecondsObject().
Timestamps need the same machinery: datetime.date.fromtimestamp() uses _PyTime_ObjectToTime_t(), datetime.datetime.fromtimestamp() uses _PyTime_ObjectToTimeval(), os.utime() uses _PyTime_ObjectToTimespec() for the items of the times tuple, and time.gmtime(), time.localtime() and time.ctime() use a private helper which also treats None as the current time.
Parametrized converters would allow to declare all of them, for example:
timeout: duration(unit='s', out='ms', round='timeout', accept={float, NoneType})
timestamp: timestamp(out='time_t', round='floor')
There are 19 parameters named "timeout" and at least 10 more of the same kind (seconds and interval of signal.setitimer(), the argument of time.sleep(), secs of the time functions, timestamp of the datetime constructors). Unifying them will also unify the error messages, which is a user visible change.
Linked PRs
- gh-156291
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- 平均マージ
- 1日 9時間
- マージ済み PR(30日)
- 558
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/cpython のほかの issue
-
docs pending
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
build type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
stdlib topic-email type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
似ている issue
-
🐛 Bug 🔔 Pending processing
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
jumpserver/jumpserver#17584 ·
-
link-check link-check:sphinx-theme
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
modelscope/DiffSynth-Studio#1702 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
OpenHands/extensions#626 · コメント 1 件 ·