Author: Benjamin Peterson <[email protected]>
Branch:
Changeset: r52139:e112d1cfaa95
Date: 2012-02-06 10:59 -0500
http://bitbucket.org/pypy/pypy/changeset/e112d1cfaa95/
Log: allow folding subscripts of BMP characters higher than surrogates
diff --git a/pypy/interpreter/astcompiler/optimize.py
b/pypy/interpreter/astcompiler/optimize.py
--- a/pypy/interpreter/astcompiler/optimize.py
+++ b/pypy/interpreter/astcompiler/optimize.py
@@ -310,7 +310,7 @@
else:
ch = 0
if (ch > 0xFFFF or
- (MAXUNICODE == 0xFFFF and 0xD800 <= ch <=
0xDFFFF)):
+ (MAXUNICODE == 0xFFFF and 0xD800 <= ch <= 0xDFFF)):
return subs
return ast.Const(w_const, subs.lineno, subs.col_offset)
diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py
b/pypy/interpreter/astcompiler/test/test_compiler.py
--- a/pypy/interpreter/astcompiler/test/test_compiler.py
+++ b/pypy/interpreter/astcompiler/test/test_compiler.py
@@ -838,7 +838,7 @@
# Just checking this doesn't crash out
self.count_instructions(source)
- def test_const_fold_unicode_subscr(self):
+ def test_const_fold_unicode_subscr(self, monkeypatch):
source = """def f():
return u"abc"[0]
"""
@@ -853,6 +853,14 @@
assert counts == {ops.LOAD_CONST: 2, ops.BINARY_SUBSCR: 1,
ops.RETURN_VALUE: 1}
+ monkeypatch.setattr(optimize, "MAXUNICODE", 0xFFFF)
+ source = """def f():
+ return u"\uE01F"[0]
+ """
+ counts = self.count_instructions(source)
+ assert counts == {ops.LOAD_CONST: 1, ops.RETURN_VALUE: 1}
+ monkeypatch.undo()
+
# getslice is not yet optimized.
# Still, check a case which yields the empty string.
source = """def f():
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit