python / python/mypy

Confusing error: incompatible type "Type[bytes]"; expected "Type[bytes]"

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

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

bug
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

Bug Report

Error message seems to indicate it requires the type it is getting. I could be reading the error message wrong, but this one confuses me.

To Reproduce

  1. put the code in a file e.g. scratchpad.py
    from typing import Type
    
    def f(class_type: Type[object]):
        if class_type in [bytes, bytearray]:
            return True
    
  2. run mypy scratchpad.py

Expected Behavior
no errors

Actual Behavior

scratchpad.py:4: error: List item 0 has incompatible type "Type[bytes]"; expected "Type[bytes]"

Your Environment

  • Mypy version used: 0.790
  • Mypy command-line flags: n/a
  • Mypy configuration options from mypy.ini (and other config files): n/a
  • Python version used: 3.8.3
  • Operating system and version: OSX 10.15.7

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

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

はじめの一歩

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

調査の方向性

まず issue の scratchpad.py の例に対して mypy を実行し、矛盾した Type[bytes] 診断を確認します。リストのメンバーシップ式に関係する型チェックの経路を追跡します。Expected Behavior に記載されているとおり、有効な例でエラーが報告されなければ完了です。

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

評価

技術スタック
python
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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