python / python/cpython

Adding read/readline() after write appends to EOF, not to the position

Open
#117,095 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

interpreter-core topic-IO type-bug
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:
with open("testfile", "r+") as my_file:

    text = my_file.write("========")
    print(my_file.readline())

Instead of writing to the beginning of the file, the program writes to the EOF even if readline() is placed after write.

CPython versions tested on:

3.8, 3.9

Operating systems tested on:

Windows

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the supplied open("testfile", "r+") example on the reported CPython versions and Windows environment. Compare the observed read position with the documented file I/O behavior; done means determining whether this is an implementation bug or expected behavior and identifying the relevant CPython change or documentation needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.