python / python/typeshed

Semaphore's value argument

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

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

主要言語
Python
スター
5.1k
フォーク
2.1k
平均マージ
1日 19時間
マージ済み PR(30日)
82

説明

Currently we assume that the semaphore's value must be an integer:
https://github.com/python/typeshed/blob/1af9de664f41b51bd3b71dac349564c5c25df810/stdlib/asyncio/locks.pyi#L88-L93

Generally this is correct, but I had a use case where I wanted to disable the semaphore without restructuring my code, so I used float("inf") as the value to ensure that it never unlocks. This works perfectly fine, because the only operations that value needs to support are:

  • Adding 1
  • Subtracting 1
  • Comparing to 0

The infinity float value does all of these fine. So I therefore wonder if we should make this type be int | Literal[math.inf]? I agree that general floats are not a good idea because they will get below 0 without triggering the wait.

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

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

はじめの一歩

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

調査の方向性

stdlib/asyncio/locks.pyi の 88-93 行目から始め、Semaphore の値のアノテーションと周辺の typeshed の規約を確認します。int | Literal[math.inf] がサポートされている動作を表現しているか確認し、その後、関連する typeshed の検証を実行します。アノテーションが infinity を受け入れつつ、一般的な floats にまでサポートを広げていなければ完了です。

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

評価

技術スタック
python
領域
devtools
issue の種類
機能追加
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
45/100

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

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