[pypy-commit] pypy default: Propagate no_nul attribute in str.__getitem__
amauryfa
noreply at buildbot.pypy.org
Mon Jan 28 19:56:38 CET 2013
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch:
Changeset: r60624:2dd7e774dce8
Date: 2013-01-28 19:53 +0100
http://bitbucket.org/pypy/pypy/changeset/2dd7e774dce8/
Log: Propagate no_nul attribute in str.__getitem__
diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -446,7 +446,8 @@
class __extend__(pairtype(SomeChar, SomeChar)):
def union((chr1, chr2)):
- return SomeChar()
+ no_nul = chr1.no_nul and chr2.no_nul
+ return SomeChar(no_nul=no_nul)
class __extend__(pairtype(SomeChar, SomeUnicodeCodePoint),
@@ -664,14 +665,14 @@
def getitem((str1, int2)):
getbookkeeper().count("str_getitem", int2)
- return SomeChar()
+ return SomeChar(no_nul=str1.no_nul)
getitem.can_only_throw = []
getitem_key = getitem
def getitem_idx((str1, int2)):
getbookkeeper().count("str_getitem", int2)
- return SomeChar()
+ return SomeChar(no_nul=str1.no_nul)
getitem_idx.can_only_throw = [IndexError]
getitem_idx_key = getitem_idx
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
@@ -2068,7 +2068,23 @@
s = a.build_types(f, [annmodel.SomeString(no_nul=True)])
assert isinstance(s, annmodel.SomeString)
assert s.no_nul
-
+
+ def test_getitem_str0(self):
+ def f(s, n):
+ if n == 1:
+ return s[0]
+ elif n == 2:
+ return s[1]
+ elif n == 3:
+ return s[1:]
+ return s
+ a = self.RPythonAnnotator()
+ a.translator.config.translation.check_str_without_nul = True
+
+ s = a.build_types(f, [annmodel.SomeString(no_nul=True),
+ annmodel.SomeInteger()])
+ assert isinstance(s, annmodel.SomeString)
+ assert s.no_nul
def test_non_none_and_none_with_isinstance(self):
class A(object):
More information about the pypy-commit
mailing list