python / python/typeshed

`configparser.RawConfigParser` stub does not account for non-string options

オープン 初心者向け
#6,820 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

説明

The stub for configparser.RawConfigParser.set has its value argument typed as str | None (source) when it can accept lots of other types and is leading to a false positive in mypy for me.

Consider this valid script:

from configparser import RawConfigParser

cfg = RawConfigParser()
cfg.add_section("default")

cfg.set("default", "some_option1", True)
r1 = cfg.get("default", "some_option1")
print(r1, type(r1))


cfg.set("default", "some_option2", 1)
r2 = cfg.get("default", "some_option2")
print(r2, type(r2))

cfg.set("default", "some_option3", b"bytes")
r3 = cfg.get("default", "some_option3")
print(r3, type(r3))

It prints:

True <class 'bool'>
1 <class 'int'>
b'bytes' <class 'bytes'>

However, mypy flags this code for the reason described above:

test.py:6: error: Argument 3 to "set" of "RawConfigParser" has incompatible type "bool"; expected "Optional[str]"
test.py:11: error: Argument 3 to "set" of "RawConfigParser" has incompatible type "int"; expected "Optional[str]"
test.py:15: error: Argument 3 to "set" of "RawConfigParser" has incompatible type "bytes"; expected "Optional[str]"

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

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

はじめの一歩

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

調査の方向性

stdlib/configparser.pyi の 133 行目付近から始め、RawConfigParser.set のシグネチャを issue に示されている動作と比較します。提供されたスクリプトを mypy で実行して誤検出を再現し、その後、boolean、integer、bytes の値がエラーなしで受け入れられることを確認するとともに、既存の get の動作も引き続きカバーされていることを確認します。

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

評価

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

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

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