This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: FileIO.readall() should raise "UnsupportedOperation" when in "w" mode
Type: behavior Stage: patch review
Components: IO, Library (Lib) Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Ziyi Wang, python-dev
Priority: normal Keywords: patch

Created on 2020-07-20 21:14 by Ziyi Wang, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 21568 open python-dev, 2020-07-20 21:23
Messages (1)
msg374027 - (view) Author: Ziyi Wang (Ziyi Wang) * Date: 2020-07-20 21:14
Here are the two test cases: the one with FileIO.readall() fails

def testReadWithWritingMode(self):
    r, w = os.pipe()
    w = os.fdopen(w, "w")
    w.write("hello")
    w.close()
    with io.FileIO(r, mode="w") as f:
        with self.assertRaises(_io.UnsupportedOperation):
            f.read()

def testReadallWithWritingMode(self):
    r, w = os.pipe()
    w = os.fdopen(w, "w")
    w.write("hello")
    w.close()
    with io.FileIO(r, mode="w") as f:
        with self.assertRaises(_io.UnsupportedOperation):
            f.readall()

With FileIO.read() raises "UnsupportedOperation" in "w" mode, I expect FileIO.readall() do the same. But in fact FileIO.readall() does not check for readable and does not raise "UnsupportedOperation" in "w"mode.

I'm happy to write a pull request if you want.
History
Date User Action Args
2022-04-11 14:59:33adminsetgithub: 85524
2022-01-24 17:23:10iritkatrielsetversions: + Python 3.11, - Python 3.6, Python 3.7, Python 3.8
2020-07-20 21:23:52python-devsetkeywords: + patch
nosy: + python-dev

pull_requests: + pull_request20711
stage: patch review
2020-07-20 21:14:00Ziyi Wangcreate