[openstack-dev] [nova] contextlib.nested and Python3 failing
Davanum Srinivas
davanum at gmail.com
Sun Aug 23 22:32:33 UTC 2015
Josh,
the test.nested() in Nova uses exactly that:
http://git.openstack.org/cgit/openstack/nova/tree/nova/test.py#n75
-- dims
On Sun, Aug 23, 2015 at 5:16 PM, Joshua Harlow <harlowja at outlook.com> wrote:
> On Fri, 21 Aug 2015 10:39:34 -0500
> "Kevin L. Mitchell" <kevin.mitchell at rackspace.com> wrote:
>
> > On Wed, 2015-08-19 at 16:51 -0700, Sylvain Bauza wrote:
> > > I was writing some tests so I added a contextlib.nested to a
> > > checked TestCase [1]. Unfortunately, contextlib.nested is no longer
> > > available in Python3 and there is no clear solution on how to
> > > provide a compatible import for both python2 and python3:
> > > - either providing a python3 compatible behaviour by using
> > > contextlib.ExitStack but that class is not available in Python 2
> > > - or provide contextlib2 for python2 (and thus adding it to the
> > > requirements)
> >
> > Actually, there should no longer be a need to use contextlib.nested.
> > We've explicitly dropped Python 2.6 compatibility, which means we're
> > expecting compatibility with Python 2.7+ only, and as of Python 2.7,
> > the 'with' statement supports accepting multiple 'as' clauses. The
> > contextlib.nested tool was really only necessary to work around that
> > functionality being missing in Python 2.6, and has been deprecated as
> > of Python 2.7 because it's no longer necessary.
>
> Other option:
>
> https://contextlib2.readthedocs.org/en/latest/#contextlib2.ExitStack
>
> Which is also in py3.x
>
> https://docs.python.org/3/library/contextlib.html#contextlib.ExitStack
>
> Might be easier to read than the multiple as clauses and such, use at
> your own will, but it's in the global-requirements (contextlib2 that
> is); so use it where applicable imho :)
>
> -Josh
>
> __________________________________________________________________________
> OpenStack Development Mailing List (not for usage questions)
> Unsubscribe: OpenStack-dev-request at lists.openstack.org?subject:unsubscribe
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>
--
Davanum Srinivas :: https://twitter.com/dims
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20150823/6d834e8a/attachment.html>
More information about the OpenStack-dev
mailing list