qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-block] [Qemu-devel] [PATCH for-3.1] qemu-iotests: Adapt to mov


From: Eduardo Habkost
Subject: Re: [Qemu-block] [Qemu-devel] [PATCH for-3.1] qemu-iotests: Adapt to moved location of StringIO module in py3
Date: Wed, 18 Jul 2018 13:01:10 -0300
User-agent: Mutt/1.9.2 (2017-12-15)

On Wed, Jul 18, 2018 at 12:22:19PM -0300, Philippe Mathieu-Daudé wrote:
> On 07/18/2018 12:05 PM, Eduardo Habkost wrote:
> > On Wed, Jul 18, 2018 at 12:02:39PM -0300, Philippe Mathieu-Daudé wrote:
> >> Hi Eduardo,
> >>
> >> On 07/18/2018 11:53 AM, Eduardo Habkost wrote:
> >>> On Tue, Jul 17, 2018 at 08:40:15PM -0300, Philippe Mathieu-Daudé wrote:
> >>> [...]
> >>>> -    import StringIO
> >>>> +    try:
> >>>> +        from StringIO import StringIO
> >>>> +    except ImportError:
> >>>> +        from io import StringIO
> >>>
> >>> Why do we need this?  Python 2.7 has io.StringIO.
> >>
> >> Python 2 works fine, the problem is the Fedora Docker image uses Python
> >> 3 and the block tests started to fail...
> > 
> > My question is: why use StringIO.StringIO on Python 2 and
> > io.StringIO on Python 3, if io.StringIO works on both Python
> > versions?
> 
> Oh I missed your question because I was not aware of this, and looked
> how this was handled in the tree (7a5d936b6fc and 5f90af8e6b).
> 
> TIL we can use "from io import StringIO" regardless the version, the
> 2->3 conversion looks a bit less absurd, thanks!

Note that it's not always an obvious conversion: on Python 3 you
need to decide if you want a text file or binary file.
io.StringIO is a text file, io.BinaryIO is a binary file.  See
https://www.mail-archive.com/address@hidden/msg545627.html
for an example where io.StringIO wasn't appropriate.

In the case of iotests.py it looks like the code expects a text
file, though.

-- 
Eduardo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]