Author: Greg Price <[email protected]>
Branch: 
Changeset: r59510:604aaf1f2218
Date: 2012-12-19 09:42 -0800
http://bitbucket.org/pypy/pypy/changeset/604aaf1f2218/

Log:    annmodel: make SomeStringOrUnicode explicitly a pure implementation
        detail

        This class exists to avoid duplicating the implementations of
        SomeString and SomeUnicodeString, but as far as any user of this
        module should be concerned those two types are totally unrelated,
        because in RPython they are unrelated.

diff --git a/pypy/annotation/binaryop.py b/pypy/annotation/binaryop.py
--- a/pypy/annotation/binaryop.py
+++ b/pypy/annotation/binaryop.py
@@ -7,7 +7,7 @@
 from pypy.tool.pairtype import pair, pairtype
 from pypy.annotation.model import SomeObject, SomeInteger, SomeBool, s_Bool
 from pypy.annotation.model import SomeString, SomeChar, SomeList, SomeDict
-from pypy.annotation.model import SomeUnicodeCodePoint, SomeStringOrUnicode
+from pypy.annotation.model import SomeUnicodeCodePoint, SomeUnicodeString
 from pypy.annotation.model import SomeTuple, SomeImpossibleValue, 
s_ImpossibleValue
 from pypy.annotation.model import SomeInstance, SomeBuiltin, SomeIterator
 from pypy.annotation.model import SomePBC, SomeFloat, s_None
@@ -19,7 +19,6 @@
 from pypy.annotation.model import read_can_only_throw
 from pypy.annotation.model import add_knowntypedata, merge_knowntypedata
 from pypy.annotation.model import SomeGenericCallable
-from pypy.annotation.model import SomeUnicodeString
 from pypy.annotation.bookkeeper import getbookkeeper
 from pypy.objspace.flow.model import Variable, Constant
 from pypy.rlib import rarithmetic
@@ -458,7 +457,8 @@
         for s_item in s_tuple.items:
             if isinstance(s_item, SomeFloat):
                 pass   # or s_item is a subclass, like SomeInteger
-            elif isinstance(s_item, SomeStringOrUnicode) and s_item.no_nul:
+            elif (isinstance(s_item, SomeString) or
+                  isinstance(s_item, SomeUnicodeString)) and s_item.no_nul:
                 pass
             else:
                 no_nul = False
diff --git a/pypy/annotation/model.py b/pypy/annotation/model.py
--- a/pypy/annotation/model.py
+++ b/pypy/annotation/model.py
@@ -211,6 +211,7 @@
     no_nul = False  # No NUL character in the string.
 
     def __init__(self, can_be_None=False, no_nul=False):
+        assert type(self) is not SomeStringOrUnicode
         if can_be_None:
             self.can_be_None = True
         if no_nul:
@@ -229,20 +230,17 @@
             d2 = d2.copy(); d2['no_nul'] = 0   # ignored
         return d1 == d2
 
+    def nonnoneify(self):
+        return self.__class__(can_be_None=False, no_nul=self.no_nul)
+
 class SomeString(SomeStringOrUnicode):
     "Stands for an object which is known to be a string."
     knowntype = str
 
-    def nonnoneify(self):
-        return SomeString(can_be_None=False, no_nul=self.no_nul)
-
 class SomeUnicodeString(SomeStringOrUnicode):
     "Stands for an object which is known to be an unicode string"
     knowntype = unicode
 
-    def nonnoneify(self):
-        return SomeUnicodeString(can_be_None=False, no_nul=self.no_nul)
-
 class SomeChar(SomeString):
     "Stands for an object known to be a string of length 1."
     can_be_None = False
diff --git a/pypy/rlib/objectmodel.py b/pypy/rlib/objectmodel.py
--- a/pypy/rlib/objectmodel.py
+++ b/pypy/rlib/objectmodel.py
@@ -132,11 +132,12 @@
     def decorator(f):
         def get_annotation(t):
             from pypy.annotation.signature import annotation
-            from pypy.annotation.model import SomeObject, SomeStringOrUnicode
+            from pypy.annotation.model import SomeObject, SomeString, 
SomeUnicodeString
             if isinstance(t, SomeObject):
                 return t
             s_result = annotation(t)
-            if isinstance(s_result, SomeStringOrUnicode):
+            if (isinstance(s_result, SomeString) or
+                isinstance(s_result, SomeUnicodeString)):
                 return s_result.__class__(can_be_None=True)
             return s_result
         def get_type_descr_of_argument(arg):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to