Inconsistant behavior of .readable() and .writable() on io.IOBase

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

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

評価

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

調査の方向性

まず、issue にあるクローズされたファイルの 2 つの例を再現し、次に io.IOBase.readable() と writable() のエントリポイントおよび関連するテストを調べます。完了の条件は、2 つのメソッドがクローズされたファイルに対して一貫性のある文書化された動作をし、オープンされたファイルに対する期待される結果を維持することです。

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

説明

extension-modules topic-IO type-bug

Bug report

The methods .readble() and .writable() on io.IOBase should return a boolean representing if the file can be read from/written to. However, calling .readable() on a closed IO file object causes a ValueError, whereas calling .writable() on a closed file returns False if the file was opened with just read permissions, but raises ValueError if it was opened with read and write permissions.

Make a folder with a text file in, then run:

f = open("hello.txt")
print(f.writable())
print(f.readable())
f.close()
print(f.writable())
print(f.readable())

This will output:

False
True
False
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: I/O operation on closed file

Then doing a similar thing, but with w+ permissions

f = open("hello.txt", "w+")
print(f.writable())
print(f.readable())
f.close()
print(f.writable())
print(f.readable())

Will output

True
True
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: I/O operation on closed file

Your environment

  • CPython versions tested on: 3.10.4
  • Operating system and architecture: Windows 64bit
主要言語
Python
スター
77.2k
フォーク
36k
平均マージ
1日 9時間
マージ済み PR(30日)
558

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

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

はじめの一歩

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

python/cpython のほかの issue

python/cpython の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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