Author: Tim Felgentreff <[email protected]>
Branch:
Changeset: r62316:5f5a391cfee4
Date: 2013-03-12 15:41 +0100
http://bitbucket.org/pypy/pypy/changeset/5f5a391cfee4/
Log: fix and test adding no_nul=True annotation to strings in result of
splitting on null-byte if maxsplit argument is not -1
diff --git a/rpython/annotator/test/test_annrpython.py
b/rpython/annotator/test/test_annrpython.py
--- a/rpython/annotator/test/test_annrpython.py
+++ b/rpython/annotator/test/test_annrpython.py
@@ -449,7 +449,6 @@
def test_str_split_nul(self):
def f(n):
return n.split('\0')[0]
-
a = self.RPythonAnnotator()
a.translator.config.translation.check_str_without_nul = True
s = a.build_types(f, [annmodel.SomeString(no_nul=False,
can_be_None=False)])
@@ -457,6 +456,15 @@
assert not s.can_be_None
assert s.no_nul
+ def g(n):
+ return n.split('\0', 1)[0]
+ a = self.RPythonAnnotator()
+ a.translator.config.translation.check_str_without_nul = True
+ s = a.build_types(g, [annmodel.SomeString(no_nul=False,
can_be_None=False)])
+ assert isinstance(s, annmodel.SomeString)
+ assert not s.can_be_None
+ assert not s.no_nul
+
def test_str_splitlines(self):
a = self.RPythonAnnotator()
def f(a_str):
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -496,7 +496,7 @@
def method_split(str, patt, max=-1):
getbookkeeper().count("str_split", str, patt)
- if patt.is_constant() and patt.const == "\0":
+ if max == -1 and patt.is_constant() and patt.const == "\0":
no_nul = True
else:
no_nul = str.no_nul
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit