Skip to content
Snippets Groups Projects
Commit 06587edd1233 authored by Pulkit Goyal's avatar Pulkit Goyal
Browse files

pycompat: make pycompat demandimport friendly

pycompat.py includes hack to import modules whose names are changed in Python 3.
We use try-except to load module according to the version of python. But this
method forces us to import the modules to raise an ImportError and hence making
it demandimport unfriendly.

This patch changes the try-except blocks to a single if-else block. To avoid
test-check-pyflakes.t complain about unused imports, pycompat.py is excluded
from the test.
parent 6ce870dba6fa
No related branches found
No related tags found
No related merge requests found
......@@ -10,5 +10,7 @@
from __future__ import absolute_import
try:
import sys
if sys.version_info[0] < 3:
import cPickle as pickle
......@@ -14,8 +16,3 @@
import cPickle as pickle
pickle.dumps
except ImportError:
import pickle
pickle.dumps # silence pyflakes
try:
import cStringIO as io
import httplib
......@@ -21,8 +18,3 @@
import httplib
httplib.HTTPException
except ImportError:
import http.client as httplib
httplib.HTTPException
try:
import Queue as _queue
import SocketServer as socketserver
......@@ -28,8 +20,3 @@
import SocketServer as socketserver
socketserver.ThreadingMixIn
except ImportError:
import socketserver
socketserver.ThreadingMixIn
try:
import urlparse
import xmlrpclib
......@@ -35,4 +22,9 @@
import xmlrpclib
xmlrpclib.Transport
except ImportError:
else:
import http.client as httplib
import io
import pickle
import queue as _queue
import socketserver
import urllib.parse as urlparse
import xmlrpc.client as xmlrpclib
......@@ -38,10 +30,2 @@
import xmlrpc.client as xmlrpclib
xmlrpclib.Transport
try:
import urlparse
urlparse.urlparse
except ImportError:
import urllib.parse as urlparse
urlparse.urlparse
......@@ -47,16 +31,5 @@
try:
import cStringIO as io
stringio = io.StringIO
except ImportError:
import io
stringio = io.StringIO
try:
import Queue as _queue
_queue.Queue
except ImportError:
import queue as _queue
stringio = io.StringIO
empty = _queue.Empty
queue = _queue.Queue
......
......@@ -6,7 +6,9 @@
run pyflakes on all tracked files ending in .py or without a file ending
(skipping binary file random-seed)
$ hg locate 'set:**.py or grep("^#!.*python")' 2>/dev/null \
$ hg locate 'set:**.py or grep("^#!.*python")' \
> -X mercurial/pycompat.py \
> 2>/dev/null \
> | xargs pyflakes 2>/dev/null | "$TESTDIR/filterpyflakes.py"
tests/filterpyflakes.py:61: undefined name 'undefinedname'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment