Skip to content

FileIO.readall() should raise "UnsupportedOperation" when in "w" mode #85524

Closed

Description

@evanWang1409
BPO 41352
Nosy @evanWang1409
PRs
  • bpo-41352: Raise UnsupportedOperation for FileIO.readall() in "w" mode #21568
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2020-07-20.21:14:00.553>
    labels = ['type-bug', '3.9', 'expert-IO', '3.11', 'library', '3.10']
    title = 'FileIO.readall() should raise "UnsupportedOperation" when in "w" mode'
    updated_at = <Date 2022-01-24.17:23:10.468>
    user = 'https://github.com/evanWang1409'

    bugs.python.org fields:

    activity = <Date 2022-01-24.17:23:10.468>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)', 'IO']
    creation = <Date 2020-07-20.21:14:00.553>
    creator = 'Ziyi Wang'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41352
    keywords = ['patch']
    message_count = 1.0
    messages = ['374027']
    nosy_count = 2.0
    nosy_names = ['python-dev', 'Ziyi Wang']
    pr_nums = ['21568']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue41352'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    Linked PRs

    Activity

    1. evanWang1409 commented on Jul 20, 2020

      evanWang1409mannequin
      MannequinAuthor

      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.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Jul 20, 2020
    3. added
      3.11only security fixes
      and removed on Jan 24, 2022
    4. transferred this issue fromon Apr 10, 2022
    5. added a commit that references this issue on Nov 7, 2025
    6. added
      3.13only security fixes
      3.14bugs and security fixes
      3.15bugs and security fixes
      and removed
      3.11only security fixes
      on Nov 7, 2025
    7. added a commit that references this issue on Nov 12, 2025
    8. vstinner commented on Nov 12, 2025

      @vstinner
      Member

      Fixed by 6f988b0.

    9. added a commit that references this issue on Dec 6, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.13only security fixes3.14bugs and security fixes3.15bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-IOtype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions