Commits

Maciej Fijalkowski committed 5769354

addition of bytearray/str/char

  • Participants
  • Parent commits 8fa0e73
  • Branches rpython-bytearray

Comments (0)

Files changed (2)

File pypy/annotation/binaryop.py

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

File pypy/annotation/test/test_annrpython.py

         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]