python / python/mypy

Should non-overlapping comparisons allowed in assertions?

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

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

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

説明

The following assertion generates an error when using --strict-equality, but perhaps it should be allowed, since an assertion can test something that should be impossible?

from typing import List

def f(x: List[int]) -> None:
    assert 'foo' not in x  # Error, but should this be okay?
    ...

I saw a few examples similar to the above in production code and had to use # type: ignore[...] with them, which didn't feel optimal.

@ilevkivskyi What do you think?

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

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

はじめの一歩

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

調査の方向性

Issue ではファイルもテストも指定されていないため、まず --strict-equality を使って例を再現し、比較エラーを報告する assertion check を追跡してください。不可能な membership assertion を受け入れるべきかを判断し、その後、示されている List[int] のケースに対する期待される診断動作とカバレッジを定義してください。

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

評価

技術スタック
python
領域
compilers
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

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

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