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

io.BufferedReader.writabe is False, but io.BufferedReader.truncate does not raise OSError #80131

steverpalmer mannequin opened this issue Feb 9, 2019 · 2 comments
3.9 only security fixes topic-IO


Copy link

steverpalmer mannequin commented Feb 9, 2019

BPO 35950
Nosy @berkerpeksag, @vadmium, @miss-islington, @steverpalmer
  • bpo-35950: Raise OSError in io.BufferedReader.truncate() #13689
  • bpo-35950: Raise UnsupportedOperation in BufferedReader.truncate() #18586
  • 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 2020-02-21.18:01:25.803>
    created_at = <Date 2019-02-09.13:36:22.181>
    labels = ['3.9', 'expert-IO']
    title = 'io.BufferedReader.writabe is False, but io.BufferedReader.truncate does not raise OSError'
    updated_at = <Date 2020-02-22.07:19:05.846>
    user = '' fields:

    activity = <Date 2020-02-22.07:19:05.846>
    actor = 'berker.peksag'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-02-21.18:01:25.803>
    closer = 'methane'
    components = ['IO']
    creation = <Date 2019-02-09.13:36:22.181>
    creator = 'steverpalmer'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35950
    keywords = ['patch']
    message_count = 2.0
    messages = ['335132', '362417']
    nosy_count = 4.0
    nosy_names = ['berker.peksag', 'martin.panter', 'miss-islington', 'steverpalmer']
    pr_nums = ['13689', '18586']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = ''
    versions = ['Python 3.9']

    Copy link
    Mannequin Author

    steverpalmer mannequin commented Feb 9, 2019

    An io.BUfferedReader object has an (inherited) writable method that returns False. io.IOBase states in the description of the writable method that "If False, write() and truncate() will raise OSError."

    However, if the BufferedReader object is constructed from a writabe io.RawIOBase object, then the truncate does not raise the exception.

    >>> import io
    >>> import tempfile
    >>> rf = tempfile.TemporaryFile(buffering=0)
    >>> rf
    <_io.FileIO name=3 mode='rb+' closefd=True>
    >>> bf = io.BufferedReader(rf)
    >>> bf.writable()
    >>> bf.truncate(0)

    Looking at file, the truncate method in the _BufferedIOMixin wrapper class delegates the truncation to it's raw attribute. If the raw element permits the truncation, then it will proceed regardless of the writable state of the wrapper class. I'd suggest that modifying the truncate method in _BufferedIOMixin to raise OSError (or Unsupported) if not self.writable() could fix this problem.

    @steverpalmer steverpalmer mannequin added 3.7 (EOL) end of life topic-IO labels Feb 9, 2019
    Copy link

    New changeset fd5116c by Berker Peksag in branch 'master':
    bpo-35950: Raise UnsupportedOperation in BufferedReader.truncate() (GH-18586)

    @methane methane added 3.9 only security fixes and removed 3.7 (EOL) end of life labels Feb 21, 2020
    @methane methane closed this as completed Feb 21, 2020
    @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
    3.9 only security fixes topic-IO
    None yet

    No branches or pull requests

    2 participants