python / python/mypy

Constrained TypeVars with Any default

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

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

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

説明

Bug Report

In python/typeshed#13683 I'm trying to change a type var to the following:

_I = TypeVar("_I", int, bytes, float, bool, default=Any)  # possibly memoryview types

Unfortunately, mypy complains: error: TypeVar default must be one of the constraint types [misc]. While this is of course generally sound advice, a default of Any should always be permissible, as this allows memoryview to stand for any possible memoryview type. Without it, users are forced to write memoryview[Any] in every instance, which is unreasonable.

Your Environment

  • Mypy version used: 1.18.2

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

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

はじめの一歩

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

調査の方向性

mypy 1.18.2 を使って、報告された TypeVar 宣言と「TypeVar default must be one of the constraint types」エラーを再現してください。まず、制約付き TypeVar のデフォルト値に対する検証箇所を特定します。このケースで Any のデフォルト値が受け入れられ、他のデフォルト値のチェックを弱めない状態になれば完了です。

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

評価

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

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

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