[issue35950] io.BufferedReader.writabe is False, but io.BufferedReader.truncate does not raise OSError

2019-02-09 Thread Steve Palmer


Change by Steve Palmer :


--
nosy: +martin.panter

___
Python tracker 
<https://bugs.python.org/issue35950>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35950] io.BufferedReader.writabe is False, but io.BufferedReader.truncate does not raise OSError

2019-02-09 Thread Steve Palmer


New submission from Steve Palmer :

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()
False
>>> bf.truncate(0)
0

Looking at _pyio.py 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.

--
components: IO
messages: 335132
nosy: steverpalmer
priority: normal
severity: normal
status: open
title: io.BufferedReader.writabe is False, but io.BufferedReader.truncate does 
not raise OSError
versions: Python 3.7

___
Python tracker 
<https://bugs.python.org/issue35950>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35869] io.BufferReader.read() returns None

2019-01-31 Thread Steve Palmer


Steve Palmer  added the comment:

The description of read in io.BufferedReader.read function states "Read and 
return size bytes, or if size is not given or negative, until EOF or if the 
read call would block in non-blocking mode."  This does mention the non-block 
mode scenario, but I can't parse this sentence.

--

___
Python tracker 
<https://bugs.python.org/issue35869>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35869] io.BufferReader.read() returns None

2019-01-31 Thread Steve Palmer


New submission from Steve Palmer :

class io.BufferedIOBase states "In addition, those methods [read(), readinto() 
and write()] can raise BlockingIOError if the underlying raw stream is in 
non-blocking mode and cannot take or give enough data; unlike their RawIOBase 
counterparts, they will never return None."

However, class.io.BufferedReader (inheriting from io.BufferedIOBase) *does* 
return None in this case.  Admittedly, io.BufferedReader does says it is 
overriding the inherited method, but I'm surprised that change in behaviour 
declared for buffered objects, is reverted to the RarIOBase behaviour on a more 
specific class.

The attached file (a little long - sorry), simulates a slow non-blocking raw 
file, which it wraps in a BufferReader to test the behaviour defined in 
BufferedIOBase.

--
files: read2.py
messages: 334630
nosy: steverpalmer
priority: normal
severity: normal
status: open
title: io.BufferReader.read() returns None
type: behavior
versions: Python 3.7
Added file: https://bugs.python.org/file48091/read2.py

___
Python tracker 
<https://bugs.python.org/issue35869>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35848] readinto is not a method on io.TextIOBase

2019-01-30 Thread Steve Palmer

Steve Palmer  added the comment:

I don't have a "real" use case.  I discovered the issue when I was developing a 
unittest suite for what it means to be "file-like".  I've been codifying the 
description in the standard library and exercising my tests against the 
built-in file-likes, such as the io.StringIO class, when it raised the 
Attribute Exception.

The more I think about it, the more like a documentation problem it feels.  For 
example, the statement "... because their signatures will vary ..." does not 
apply to readinto in the cases where it is defined.

For completeness, the note in io.TextIOBase stating "There is no readinto() 
method because Python’s character strings are immutable." would also need to be 
removed as part of a documentation fix.

(It's also nice when solutions result in less "stuff". :-)

--

___
Python tracker 
<https://bugs.python.org/issue35848>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35848] readinto is not a method on io.TextIOBase

2019-01-29 Thread Steve Palmer


Steve Palmer  added the comment:

I agree with Karthikeyan that the method does not apply in the io.TextIOBase 
class context.  I'm sorry that I didn't spot the note in the description of 
io.TextIOBase - though I think that it is easy to miss.

I'd suggest that there are two ways to clear this up:

1. change only the documentation to read "Even though IOBase does not declare 
read() or write() because their signatures will vary, implementations and 
clients should consider those methods part of the interface."  (deleting 
reference to readinto())

2. change the standard library for io.TextIOBase to add a method readinto which 
will raise an UnsupportedOperation.

With option 1, the descriptions for io.RawIOBase and io.BufferedIOBase both 
include description of the readinto method, so nothing is lost by removing 
mention of it at the io.IOBase level of the hierarchy.  In any case, readinto() 
is not defined on the io.IOBase class.

>>> 'readinto' not in dir(io.IOBase)
True

With option 2, it feels like this is closer to the design intent of a common 
interface over similar but distinguished classes.  It also avoids removing 
things from the documentation in case someone already has some expectations of 
the behaviour.

--

___
Python tracker 
<https://bugs.python.org/issue35848>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35848] readinto is not a method on io.TextIOBase

2019-01-29 Thread Steve Palmer


New submission from Steve Palmer :

class io.IOBase states "Even though IOBase does not declare read(), readinto(), 
or write() because their signatures will vary, implementations and clients 
should consider those methods part of the interface. Also, implementations may 
raise a ValueError (or UnsupportedOperation) when operations they do not 
support are called."  However, even though class io.TextIOBase is described as 
inheriting from io.IOBase, a call to readinto method returns AttributeError 
exception indicating no readinto attribute, inconsistent with the documentation.

--
components: IO
messages: 334507
nosy: steverpalmer
priority: normal
severity: normal
status: open
title: readinto is not a method on io.TextIOBase
type: behavior
versions: Python 3.7

___
Python tracker 
<https://bugs.python.org/issue35848>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com