Some string `in` `Union[bytes, str]` does not produce an error
オープン
まだ誰も着手していません。
bug
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Given the following code
from typing import Union
foo: Union[str, bytes]
"zoo" in foo # no error
"zoo" + foo # err: Unsupported operand types for + ("str" and "bytes")
I would have expected that mypy complains about str not compatible with bytes just like it does for the + operand.
I've tried the current typeshed version at 3d140160 because it just looked like there was a change here in Oct 2020 after mypy 0.790.
For example it now defines for class(str):
def __contains__(self, o: Union[str, str]) -> bool: ... # type: ignore
...
def __iter__(self) -> Iterator[str]: ...
(__contains__ does not trigger here but its Union[str, str] is weird.)
Your Environment
mypy 0.790
python 3.8
builtin typeshed and @3d140160
Win 10
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず mypy 0.790 で Union[str, bytes] の例を再現し、次に str.contains の typeshed 定義と、関連する Union の処理を調べます。"zoo" in foo と "zoo" + foo の診断を比較し、包含式が加算式と一貫して互換性のない str/bytes のケースを報告すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100