Unknown `DefaultNamedArg` raises type incompatibility errors
オープン
まだ誰も着手していません。
bug
topic-calls
topic-type-variables
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
🐛 Bug Report
DefaultNamedArg may cause signature compatibility errors. Observed when a function has a default keyword argument in signature and is passed to be used as a function without that particular keyword argument.
To Reproduce
from typing import List, AnyStr
from glob import glob
import itertools as it
def expand_patterns(
pats: List[AnyStr],
sort=True
):
paths = it.chain(map(glob, pats))
# Argument 1 to "map" has incompatible type "Callable[[AnyStr, DefaultNamedArg(bool, 'recursive')], List[AnyStr]]"; expected "Callable[[AnyStr], List[AnyStr]]"
if sort:
paths = sorted(paths)
return paths
Expected Behavior
Not sure if this ought to happen, but I'd expect a function like foo(x: int, y='y') to be peacefully passable to a function expecting Callable[[int], Any].
Actual Behavior
# Argument 1 to "map" has incompatible type "Callable[[AnyStr, DefaultNamedArg(bool, 'recursive')], List[AnyStr]]"; expected "Callable[[AnyStr], List[AnyStr]]"
Your Environment
- Mypy version used: 0.782
- Mypy command-line flags: Default of VSCode
- Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.7.7
- Operating system and version: Windows 10, 2004
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、glob、map、Callable の互換性、DefaultNamedArg を含む、提供された Python の例を再現します。mypy が Callable のシグネチャをどのように比較するかを追跡し、デフォルトのキーワード引数が意図された互換性ルールに従って処理されること、そして報告された非互換性が解消されることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100