Conditionalizing imports Python2 - Python3

Wasim Thabraze waseem.tabraze at gmail.com
Sun Feb 28 07:09:12 UTC 2016


Hello everyone,

I'm currently working on conditionalizing imports (Moving towards Python3 -
GSoC).

In '/contrib' folder I found some issues with the imports.

1. In 'casemash.py'  we are importing 'builtins' as 'import __builtin__'.
This works in Python 2 but Python 3 gives an ImportError. To resolve this
we need to change it to  'import builtins'. This works in both Python 2 and
Python 3.

2. In 'hgclient.py' we import 'cStringIO' but this raises an ImportError in
Python 3. Python 3 version of 'cStringIO' is 'from io import StringIO'. So
changing 'import cStringIO' to 'from io import StringIO'  would work in
both Python 2 and Python 3.

3. In 'import-checker.py' we import http server module as 'BaseHTTPServer'.
This doesn't work in Python 3. Raises an Import Error. Changing 'import
BaseHTTPServer' to 'from http import server' would work fine in both Python
2 and 3.

We can also resolve them by making conditional imports as follows for all
such imports.

>>> try:...     import BaseHTTPServer... except ImportError:...     from http import server


I'm currently working on this task of conditionalizing imports and other
tasks mentioned.

I feel glad if I can receive feedback about it.

Thank You.

Regards,
Wasim
www.thabraze.me
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20160228/ee135e32/attachment.html>


More information about the Mercurial-devel mailing list