Commits

timfel committed 5f5a391

fix and test adding no_nul=True annotation to strings in result of splitting on null-byte if maxsplit argument is not -1

Comments (0)

Files changed (2)

rpython/annotator/test/test_annrpython.py

     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)])
         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):

rpython/annotator/unaryop.py

 
     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