python / python/mypy

Using TypeVar as typing for a function argument disables the --strict-equality check

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

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

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

説明

Bug Report

When using a TypeVar as typing for a function parameter, the --strict-equality checks are no longer executed.

To Reproduce

from typing import TypeVar

T = TypeVar("T", int, str)


def a(x: T) -> None:
    1 == "a"


def b(x: int | str) -> None:
    1 == "a"

a(1)
b(1)

Playground: https://mypy-play.net/?mypy=master&python=3.10&flags=strict&gist=60fa0e9e47a0ed5683357b1fa2611477

Expected Behavior

I would expect both functions a() and b() to raise the comparison-overlap error.

Actual Behavior

Only function b() where there is no TypeVar used raises the comparison-overlap error.

Note that other, standard, mypy checks are executed and flagged in both functions.

Your Environment

  • Mypy version used: Checked with multiple (1.4.1, 1.7.0, master branch)
  • Mypy command-line flags: --strict or --strict-equality
  • Mypy configuration options from mypy.ini (and other config files): -
  • Python version used: 3.10, 3.11

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

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

はじめの一歩

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

調査の方向性

提供された再現コードを --strict-equality 付きで実行し、関数 a() と b() の診断を比較します。constrained TypeVar パラメーターに対する mypy の strict-equality の処理を追跡します。両方の比較で comparison-overlap が報告され、回帰テストのカバレッジでその動作が確認されれば完了です。

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

評価

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

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

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