Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

truncate() changes current stream position #76409

Closed
andreymal mannequin opened this issue Dec 5, 2017 · 4 comments
Closed

truncate() changes current stream position #76409

andreymal mannequin opened this issue Dec 5, 2017 · 4 comments
Labels
3.7 (EOL) end of life topic-IO type-bug An unexpected behavior, bug, or error

Comments

@andreymal
Copy link
Mannequin

andreymal mannequin commented Dec 5, 2017

BPO 32228
Nosy @pitrou, @nitishch, @andreymal
PRs
  • bpo-32228: Reset raw_pos after unwinding the raw stream #4858
  • [3.6] bpo-32228: Reset raw_pos after unwinding the raw stream (GH-4858) #5389
  • Files
  • wtf1.py
  • 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 = <Date 2018-01-28.17:44:00.391>
    created_at = <Date 2017-12-05.23:19:14.742>
    labels = ['type-bug', '3.7', 'expert-IO']
    title = 'truncate() changes current stream position'
    updated_at = <Date 2018-01-28.17:44:00.388>
    user = 'https://github.com/andreymal'

    bugs.python.org fields:

    activity = <Date 2018-01-28.17:44:00.388>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-01-28.17:44:00.391>
    closer = 'pitrou'
    components = ['IO']
    creation = <Date 2017-12-05.23:19:14.742>
    creator = 'andreymal'
    dependencies = []
    files = ['47321']
    hgrepos = []
    issue_num = 32228
    keywords = ['patch']
    message_count = 4.0
    messages = ['307698', '310962', '310973', '310974']
    nosy_count = 3.0
    nosy_names = ['pitrou', 'nitishch', 'andreymal']
    pr_nums = ['4858', '5389']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue32228'
    versions = ['Python 3.6', 'Python 3.7']

    @andreymal
    Copy link
    Mannequin Author

    andreymal mannequin commented Dec 5, 2017

    See attached file.

    As documentation about "truncate" says, "The current stream position isn’t changed." This is true for most cases. But this is not true for "wtf1.py" example. If you run it with Linux (Tested Debian 8 and Arch; Windows was not tested by me) and Python 3.3+ (or with Python 2.7 using backported "io" module), then these lines:

    print('tell:', fp.tell())
    print('truncate:', fp.truncate())
    print('tell again:', fp.tell())

    prints this:

    tell: 4098
    truncate: 4098
    tell again: 4

    As you can see, "tell" before truncate and "tell" after truncate are different. Looks like bug.

    This bug will not reproduce with Python 2.7 and builtin "open" function; it affects only "io.open".

    @andreymal andreymal mannequin added the topic-IO label Dec 5, 2017
    @andreymal andreymal mannequin changed the title truncate() changes tell() result truncate() changes current stream position Dec 5, 2017
    @andreymal andreymal mannequin added the type-bug An unexpected behavior, bug, or error label Dec 5, 2017
    @pitrou
    Copy link
    Member

    pitrou commented Jan 28, 2018

    New changeset 059f58c by Antoine Pitrou (Nitish Chandra) in branch 'master':
    bpo-32228: Reset raw_pos after unwinding the raw stream (bpo-4858)
    059f58c

    @pitrou
    Copy link
    Member

    pitrou commented Jan 28, 2018

    New changeset 1d896ed by Antoine Pitrou in branch '3.6':
    [3.6] bpo-32228: Reset raw_pos after unwinding the raw stream (GH-4858) (bpo-5389)
    1d896ed

    @pitrou
    Copy link
    Member

    pitrou commented Jan 28, 2018

    I've now pushed Nitish's fix to 3.7 and 3.6. I have no interest in backporting to 2.7 at this point. Closing!

    @pitrou pitrou added the 3.7 (EOL) end of life label Jan 28, 2018
    @pitrou pitrou closed this as completed Jan 28, 2018
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life topic-IO type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant