python / python/cpython

pprint.isreadable returns True for non-eval-able float and complex specials

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

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

stdlib type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Issue

isreadable is documented as returning True if the object's repr is readable by the interpreter — implying eval(pformat(obj)) == obj. For float and complex non-finite values, isreadable returns True, but the roundtrip fails — eval raises NameError since inf and nan aren't valid Python expressions.

Reproducer

import pprint

print(pprint.isreadable(float('inf')))        # True — but eval('inf') raises NameError
print(pprint.isreadable(float('nan')))        # True
print(pprint.isreadable(complex(float('inf'), 0)))  # True
CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs
  • gh-145116
  • gh-145120

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

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

はじめの一歩

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

調査の方向性

pprint.isreadable から始め、非有限の float 値および complex 値について reproducer を実行します。それらの表現がどのように分類されるかを追跡し、表現の評価で NameError が発生する場合に isreadable が値を読み取り可能だと主張しなくなっていることを確認します。これらのケースに対する焦点を絞ったテストを追加または更新します。

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

評価

技術スタック
python
領域
tooling
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
25/100

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

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