mypy doesn't understand partial unpacking with star arguments
オープン
まだ誰も着手していません。
bug
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
While working on https://github.com/qutebrowser/qutebrowser/pull/5317 I think I may have found a bug in mypy. The following code looks correct, and runs fine on my machine.
To Reproduce
- Save the following code to file
/tmp/reproducer.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: fenc=utf-8:et:ts=4:sts=4:sw=4:fdm=marker
from typing import Optional, Sequence, Mapping
import collections
class ModuleInfo:
def __init__(
self,
name: str,
version_attributes: Sequence[str],
min_version: Optional[str] = None
):
self.name = name
self._version_attributes = version_attributes
self.min_version = min_version
MODULE_INFO: Mapping[str, ModuleInfo] = collections.OrderedDict([
(name, ModuleInfo(name, *args))
for (name, *args) in
[
('sip', ['SIP_VERSION_STR']),
('colorama', ['VERSION', '__version__']),
('pypeg2', ['__version__']),
('jinja2', ['__version__']),
('pygments', ['__version__']),
('yaml', ['__version__']),
('adblock', ['__version__'], "0.3.2"),
('cssutils', ['__version__']),
('attr', ['__version__']),
('PyQt5.QtWebEngineWidgets', []),
('PyQt5.QtWebEngine', ['PYQT_WEBENGINE_VERSION_STR']),
('PyQt5.QtWebKitWidgets', []),
]
])
- Run
mypy /tmp/reproducer.py.
Expected Behavior
There should be no type errors.
Actual Behavior
The output of the command in step 2 returns:
reproducer.py:19: error: List comprehension has incompatible type List[Tuple[Sequence[str], ModuleInfo]]; expected List[Tuple[str, ModuleInfo]]
reproducer.py:19: error: Argument 1 to "ModuleInfo" has incompatible type "Sequence[str]"; expected "str"
reproducer.py:19: error: Argument 2 to "ModuleInfo" has incompatible type "*List[Sequence[str]]"; expected "Optional[str]"
Found 3 errors in 1 file (checked 1 source file)
Your Environment
- Mypy version used:
mypy 0.790 - Mypy command-line flags:
mypy /tmp/reproducer.py - Mypy configuration options from
mypy.ini(and other config files): None, I think - Python version used:
Python 3.8.6 - Operating system and version: Gentoo Linux
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
/tmp/reproducer.py の例から始め、報告されている Python と mypy のバージョンを使って mypy /tmp/reproducer.py を実行します。型チェッカーがアスタリスク付きタプルアンパックとコンストラクター呼び出しをどのように処理するかを追跡し、その後、reproducer が型エラーを報告しないように動作を更新します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 45/100