[pypy-commit] pypy wrap-bytes: hg merge SomeString-charclass
amauryfa
noreply at buildbot.pypy.org
Tue Jul 15 15:43:53 CEST 2014
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: wrap-bytes
Changeset: r72444:a5ac58fb49e1
Date: 2014-07-13 21:42 +0200
http://bitbucket.org/pypy/pypy/changeset/a5ac58fb49e1/
Log: hg merge SomeString-charclass
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -241,7 +241,8 @@
if TLS.check_str_without_nul:
if self.no_nul != other.no_nul:
return False
- return True
+ return (self.is_ascii == other.is_ascii and
+ self.is_utf8 == other.is_utf8)
def union(self, other):
return self
@@ -670,8 +671,8 @@
s_Bool = SomeBool()
s_Int = SomeInteger()
s_ImpossibleValue = SomeImpossibleValue()
-s_Str0 = SomeString(charkind=NoNulChar)
-s_Unicode0 = SomeUnicodeString(charkind=NoNulChar)
+s_Str0 = SomeString(charkind=NoNulChar())
+s_Unicode0 = SomeUnicodeString(charkind=NoNulChar())
# ____________________________________________________________
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
@@ -3869,6 +3869,19 @@
assert s.can_be_None
assert s.charkind.no_nul
+ def test_contains_ascii(self):
+ chars = '01234567890abcdef'
+ def f(i):
+ if i in chars:
+ return i
+ else:
+ return None
+ a = self.RPythonAnnotator()
+ s = a.build_types(f, [annmodel.SomeString(charkind=annmodel.AnyChar())])
+ assert isinstance(s, annmodel.SomeString)
+ assert s.can_be_None
+ assert s.charkind.is_ascii
+
def test_no___call__(self):
class X(object):
def __call__(self):
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -9,7 +9,7 @@
SomeString, SomeChar, SomeList, SomeDict, SomeTuple, SomeImpossibleValue,
SomeUnicodeCodePoint, SomeInstance, SomeBuiltin, SomeBuiltinMethod,
SomeFloat, SomeIterator, SomePBC, SomeNone, SomeType, s_ImpossibleValue,
- s_Bool, s_None, unionof, add_knowntypedata, NoNulChar,
+ s_Bool, s_None, unionof, add_knowntypedata, NoNulChar, AsciiChar,
HarmlesslyBlocked, SomeWeakRef, SomeUnicodeString, SomeByteArray)
from rpython.annotator.bookkeeper import getbookkeeper, immutablevalue
from rpython.annotator import builtin
@@ -506,7 +506,17 @@
return self.basestringclass(charkind=self.charkind)
def op_contains(self, s_element):
- if s_element.is_constant() and s_element.const == "\0":
+ if self.is_constant() and self.const.isalnum():
+ r = SomeBool()
+ bk = getbookkeeper()
+ op = bk._find_current_op(opname="contains", arity=2, pos=0, s_type=self)
+ # raise TypeError(op.args)
+ knowntypedata = {}
+ add_knowntypedata(knowntypedata, True, [op.args[1]],
+ SomeString(charkind=AsciiChar()))
+ r.set_knowntypedata(knowntypedata)
+ return r
+ elif s_element.is_constant() and s_element.const == "\0":
r = SomeBool()
bk = getbookkeeper()
op = bk._find_current_op(opname="contains", arity=2, pos=0, s_type=self)
diff --git a/rpython/rlib/types.py b/rpython/rlib/types.py
--- a/rpython/rlib/types.py
+++ b/rpython/rlib/types.py
@@ -51,7 +51,7 @@
def str0():
- return model.s_str0
+ return model.s_Str0
def char():
More information about the pypy-commit
mailing list