python / python/mypy

Feature request: option that completely disallows typing.cast

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

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

feature topic-casts
主要言語
Python
スター
20.6k
フォーク
3.3k
平均マージ
1日 18時間
マージ済み PR(30日)
54

説明

Feature

An option that disallows use of typing.cast, eg --disallow-casts

Pitch

cast() gets around static type safety without ensuring dynamic type correctness. Sometimes you have to use it—you know how it is—but it's not ideal. (For instance, mypy documentation seems to imply the main use of cast is when the typechecker or type annotations aren't quite good enough.) That means, in my opinion, cast is a great candidate to have a option disallowing its use, to ensure code quality in codebases where it is not needed.

I also think this option should be enabled in strict mode, but I suspect other people might disagree.

This proposal is distinct from the --warn-redundant-casts option that already exists, but is somewhat similar.

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

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

はじめの一歩

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

調査の方向性

まず、既存の --warn-redundant-casts オプションがどのように実装されているかを確認し、これを strict mode に含めるべきかどうかについての議論を読んでください。typing.cast の想定される扱いと設定動作を定義し、その後、新しいオプションが cast を拒否すること、および選択した strict mode の動作がテストでカバーされていることを確認してください。

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

評価

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

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

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