[pypy-commit] pypy rpython-bytearray: addition of bytearray/str/char
fijal
noreply at buildbot.pypy.org
Sun Dec 23 19:44:11 CET 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: rpython-bytearray
Changeset: r59541:57693544dda7
Date: 2012-12-23 20:39 +0200
http://bitbucket.org/pypy/pypy/changeset/57693544dda7/
Log: addition of bytearray/str/char
diff --git a/pypy/annotation/binaryop.py b/pypy/annotation/binaryop.py
--- a/pypy/annotation/binaryop.py
+++ b/pypy/annotation/binaryop.py
@@ -420,6 +420,22 @@
can_be_None = b1.can_be_None or b2.can_be_None
return SomeByteArray(can_be_None=can_be_None)
+ def add((b1, b2)):
+ result = SomeByteArray()
+ if b1.is_immutable_constant() and b2.is_immutable_constant():
+ result.const = b1.const + b2.const
+ return result
+
+class __extend__(pairtype(SomeString, SomeByteArray),
+ pairtype(SomeByteArray, SomeString),
+ pairtype(SomeChar, SomeByteArray),
+ pairtype(SomeByteArray, SomeChar)):
+ def add((b1, b2)):
+ result = SomeByteArray()
+ if b1.is_immutable_constant() and b2.is_immutable_constant():
+ result.const = b1.const + b2.const
+ return result
+
class __extend__(pairtype(SomeChar, SomeChar)):
def union((chr1, chr2)):
diff --git a/pypy/annotation/test/test_annrpython.py b/pypy/annotation/test/test_annrpython.py
--- a/pypy/annotation/test/test_annrpython.py
+++ b/pypy/annotation/test/test_annrpython.py
@@ -3826,6 +3826,21 @@
a = self.RPythonAnnotator()
assert isinstance(a.build_types(f, []), annmodel.SomeByteArray)
+ def test_bytearray_add(self):
+ def f(a):
+ return a + bytearray("xyz")
+
+ a = self.RPythonAnnotator()
+ assert isinstance(a.build_types(f, [annmodel.SomeByteArray()]),
+ annmodel.SomeByteArray)
+ a = self.RPythonAnnotator()
+ assert isinstance(a.build_types(f, [str]),
+ annmodel.SomeByteArray)
+ a = self.RPythonAnnotator()
+ assert isinstance(a.build_types(f, [annmodel.SomeChar()]),
+ annmodel.SomeByteArray)
+
+
def g(n):
return [0,1,2,n]
More information about the pypy-commit
mailing list