python / python/mypy

Variadic `*args` where `args: Union[Tuple[...], Tuple[...], ...]` are _never_ checked [False Negative]

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

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

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

説明

Bug Report

When args is a Union of two or more fixed-length Tuples, and some_func() is callable, the following call is always accepted without error (regardless of what's in the tuples!):

some_func(*args)

To Reproduce

[mypy-play.net]

from __future__ import annotations

from typing import (
        Tuple,
        Union,
        )

class ClassA: pass
class ClassB: pass
class ClassC: pass

def some_func(value: ClassA, /) -> None:
    pass

u_bc: Union[Tuple[ClassB], Tuple[ClassC]]
some_func(*u_bc)  # expected: [type-arg]; got: no error

Expected Behavior

Mypy should notice that one or more of the Tuples that make up the Union are not appropriate for the callable, and complain about the argument types accordingly.

Put another way, mypy should examine each possibility posed by the Union in turn, and complain if any of them isn't suitable for the variadic call.

Actual Behavior

Mypy always accepts variadic arguments of this form, without any regard to the contents of the Tuples that make up the Union.

Your Environment

  • Mypy version used: 1.9.0 (also checked 1.5, 1.0; this doesn't appear to be a recent regression)
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.8, 3.12

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

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

はじめの一歩

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

調査の方向性

mypy-play.net の再現例を出発点とし、示されている Python 3.12 の例を実行して、mypy が固定長 Tuple の Union からの可変長 *args をどのように処理するかを調査します。Expected Behavior に記載されているとおり、互換性のないタプルの選択肢に対して呼び出しで引数型エラーが報告されれば完了です。

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

評価

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

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

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