Skip to content

Commit 8fdba0f

Browse files
committed
Use a single pyexec() utility function to fix compatibility issues
While the current setup (where 2.x uses the exec statement and 3.x uses the exec() function) works at run-time, it causes problem while byte-compiling the util modules for their non-appropriate interpreter versions: File "/usr/lib64/python2.7/site-packages/couchdb/util3.py", line 17 pyexec = exec ^ SyntaxError: invalid syntax File "/usr/lib64/python3.3/site-packages/couchdb/util2.py", line 19 exec code in gns, lns ^ SyntaxError: invalid syntax There doesn't appear to be an easy way to exclude some files from installation based on the installing Python version, but it turns out the 2.x exec statement can also take its arguments as a tuple, such that the 2.x and 3.x versions can be used with the same syntax. However, Python 2.7 has a bug (#21591) that prevents this from working in the context we use exec in (in a function that also contains a nested function), due to a bad implementation that enables the arguments-as-tuple functionality. We thus need a helper function after all, to pull it out of that context.
1 parent 23eb71c commit 8fdba0f

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

couchdb/util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@
44
from couchdb.util2 import *
55
else:
66
from couchdb.util3 import *
7+
8+
def pyexec(code, gns, lns):
9+
# http://bugs.python.org/issue21591
10+
exec(code, gns, lns)

couchdb/util2.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11

22
__all__ = [
33
'StringIO', 'urlsplit', 'urlunsplit', 'urlquote', 'urlunquote',
4-
'urlencode', 'utype', 'ltype', 'pyexec', 'strbase', 'funcode',
5-
'urlparse',
4+
'urlencode', 'utype', 'ltype', 'strbase', 'funcode', 'urlparse',
65
]
76

87
utype = unicode
@@ -15,8 +14,5 @@
1514
from urllib import unquote as urlunquote
1615
from urllib import urlencode
1716

18-
def pyexec(code, gns, lns):
19-
exec code in gns, lns
20-
2117
def funcode(fun):
2218
return fun.func_code

couchdb/util3.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11

22
__all__ = [
33
'StringIO', 'urlsplit', 'urlunsplit', 'urlquote', 'urlunquote',
4-
'urlencode', 'utype', 'ltype', 'pyexec', 'strbase', 'funcode',
5-
'urlparse',
4+
'urlencode', 'utype', 'ltype', 'strbase', 'funcode', 'urlparse',
65
]
76

87
utype = str
@@ -14,7 +13,5 @@
1413
from urllib.parse import quote as urlquote
1514
from urllib.parse import unquote as urlunquote
1615

17-
pyexec = exec
18-
1916
def funcode(fun):
2017
return fun.__code__

0 commit comments

Comments
 (0)