Greg Price  committed 604aaf1

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.

  • Participants
  • Parent commits 8be991a

Comments (0)

Files changed (3)

File pypy/annotation/

 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
 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
         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:
                 no_nul = False

File pypy/annotation/

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

File pypy/rlib/

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