Author: Amaury Forgeot d'Arc <[email protected]>
Branch: SomeString-charclass
Changeset: r72443:e9087bbe0338
Date: 2014-07-13 21:40 +0200
http://bitbucket.org/pypy/pypy/changeset/e9087bbe0338/
Log: Fix, and add support for "x in 'ascii_str'".
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
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)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit