GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Document that the built-in open() when called with a file descriptor ignores "mode" argument · Issue #95498 · python/cpython

Document that the built-in open() when called with a file descriptor ignores "mode" argument #95498

New issue
Copy link
New issue
Copy link
Open
Open
Document that the built-in open() when called with a file descriptor ignores "mode" argument#95498
Copy link
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirtopic-IO

Description

@piotr-dobrogost
piotr-dobrogost
opened on Jul 31, 2022
Issue body actions

At https://docs.python.org/3/library/functions.html#open, in the documentation of the mode argument there is no information that this argument is ignored when the function is called with a file descriptor instead of a path.

See Why does os.fdopen ignore mode? SO question. The question talks about os.fdopen() but according to https://docs.python.org/3/library/os.html#os.fdopen

This is an alias of the open() built-in function and accepts the same arguments.

so I think it should be enough to place the information in the documentation of the mode argument of the built-in open() function. This way it would document the built-in open() function but also the os.fdopen() function by virtue of the latter being an alias of the former.

Linked PRs

  • gh-95498: Document open() behavior with file descriptors #159324
  • gh-95498: Document open() behavior with file descriptors #161193

Activity

  1. piotr-dobrogost
    added
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    on Jul 31, 2022
  2. ronaldoussoren
    added
    topic-IO
    on Jul 31, 2022
  3. tiran commented on Jul 31, 2022

    @tiran
    tiran
    on Jul 31, 2022
    Member
    More actions

    builtin open() does not ignore the mode parameter. The argument is used to determinate the type of object. The open() function does not verify that the properties of the fd matches the arguments:

    >>> fd = os.open("testfile.txt", os.O_WRONLY | os.O_CREAT)
    
    >>> f1 = open(fd, mode="r")
    >>> f1
    <_io.TextIOWrapper name=3 mode='r' encoding='UTF-8'>
    >>> f1.read()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    OSError: [Errno 9] Bad file descriptor
    >>> f1.write("foo")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    io.UnsupportedOperation: not writable
    
    >>> f2 = open(fd, mode="rb")
    >>> f2
    <_io.BufferedReader name=3>
    
  4. piotr-dobrogost commented on Jul 31, 2022

    @piotr-dobrogost
    piotr-dobrogost
    on Jul 31, 2022
    Author
    More actions

    The open() function does not verify that the properties of the fd matches the arguments

    Well, this is surprising. If the properties of the fd can't be verified (or it's undesired for them to be verified for some reason) then it should be clearly stated in the documentation that it's a caller's responsibility to match them with the value of the mode argument. Also in this case there should be information on what exactly matching the properties of the fd means.

  5. kevinprimeraquecreo-stack
    added this to Project_VKon Oct 18, 2026
  6. github-project-automation
    moved this to Todo in Project_VKon Oct 18, 2026
  7. kevinprimeraquecreo-stack
    added this to Project_VKon Oct 18, 2026
  8. raihanshiras
    added a commit that references this issue on Oct 29, 2026

    Merge pull request #1 from raihanshiras/pythongh-95498-open-fd-docs

    4acc5a3
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

    docsDocumentation in the Doc dirDocumentation in the Doc dirtopic-IO

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.