[pypy-commit] pypy union-side-effects: Explicitly forbid comparisons between str and unicode
rlamy
pypy.commits at gmail.com
Sun Sep 4 19:17:10 EDT 2016
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: union-side-effects
Changeset: r86873:e1f64f1f25cc
Date: 2016-09-05 00:16 +0100
http://bitbucket.org/pypy/pypy/changeset/e1f64f1f25cc/
Log: Explicitly forbid comparisons between str and unicode
diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -641,6 +641,20 @@
result.const = str1.const + str2.const
return result
+for cmp_op in [op.lt, op.le, op.eq, op.ne, op.gt, op.ge]:
+ @cmp_op.register(SomeUnicodeString, SomeString)
+ @cmp_op.register(SomeUnicodeString, SomeChar)
+ @cmp_op.register(SomeString, SomeUnicodeString)
+ @cmp_op.register(SomeChar, SomeUnicodeString)
+ @cmp_op.register(SomeUnicodeCodePoint, SomeString)
+ @cmp_op.register(SomeUnicodeCodePoint, SomeChar)
+ @cmp_op.register(SomeString, SomeUnicodeCodePoint)
+ @cmp_op.register(SomeChar, SomeUnicodeCodePoint)
+ def cmp_str_unicode(annotator, v1, v2):
+ raise AnnotatorError(
+ "Comparing byte strings with unicode strings is not RPython")
+
+
class __extend__(pairtype(SomeInteger, SomeList)):
def mul((int1, lst2)):
diff --git a/rpython/rlib/runicode.py b/rpython/rlib/runicode.py
--- a/rpython/rlib/runicode.py
+++ b/rpython/rlib/runicode.py
@@ -1367,7 +1367,7 @@
oc = ord(ch)
# Escape quotes
- if quotes and (oc == quote or ch == '\\'):
+ if quotes and (oc == quote or ch == u'\\'):
result.append(STR('\\'))
result.append(CHR(oc))
pos += 1
@@ -1390,13 +1390,13 @@
pos -= 1
# Map special whitespace to '\t', \n', '\r'
- if ch == '\t':
+ if ch == u'\t':
result.append(STR('\\t'))
- elif ch == '\n':
+ elif ch == u'\n':
result.append(STR('\\n'))
- elif ch == '\r':
+ elif ch == u'\r':
result.append(STR('\\r'))
- elif ch == '\\':
+ elif ch == u'\\':
result.append(STR('\\\\'))
# Map non-printable or non-ascii to '\xhh' or '\uhhhh'
More information about the pypy-commit
mailing list