[pypy-commit] pypy py3.6: Fix default values for first_escape_error_char

tdziopa pypy.commits at gmail.com
Sun Apr 22 20:30:05 EDT 2018


Author: Tomasz Dziopa <tomek.dziopa at gmail.com>
Branch: py3.6
Changeset: r94423:cd4db20fa471
Date: 2018-04-22 23:41 +0100
http://bitbucket.org/pypy/pypy/changeset/cd4db20fa471/

Log:	Fix default values for first_escape_error_char

	This PR fixes the RPython annotation errors for
	PyString_DecodeEscape.

diff --git a/pypy/interpreter/pyparser/parsestring.py b/pypy/interpreter/pyparser/parsestring.py
--- a/pypy/interpreter/pyparser/parsestring.py
+++ b/pypy/interpreter/pyparser/parsestring.py
@@ -117,8 +117,10 @@
     v, first_escape_error_char = PyString_DecodeEscape(
         space, substr, 'strict', encoding)
 
-    if first_escape_error_char != -1:
-        space.warn("invalid excape sequence '\\%c'" % first_escape_error_char,
+    if first_escape_error_char != '':
+        space.warn(
+            space.newtext("invalid excape sequence '\\%c'"
+                             % first_escape_error_char),
             space.w_DeprecationWarning)
 
     return space.newbytes(v)
@@ -164,7 +166,7 @@
     builder = StringBuilder(len(s))
     ps = 0
     end = len(s)
-    first_escape_error_char = -1
+    first_escape_error_char = ''
     while ps < end:
         if s[ps] != '\\':
             # note that the C code has a label here.
@@ -244,7 +246,7 @@
             builder.append('\\')
             ps -= 1
             assert ps >= 0
-            if first_escape_error_char == -1:
+            if first_escape_error_char == '':
                 first_escape_error_char = ch
             continue
             # an arbitry number of unescaped UTF-8 bytes may follow.


More information about the pypy-commit mailing list