def type(self, *moreargs): if moreargs: raise Exception('type() called with more than one argument') r = SomeType() bk = getbookkeeper() op = bk._find_current_op(opname="type", arity=1, pos=0, s_type=self) r.is_type_of = [op.args[0]] return r
def annotationoftype(t, bookkeeper=False): from rpython.rtyper import extregistry """The most precise SomeValue instance that contains all objects of type t.""" assert isinstance(t, (type, types.ClassType)) if t is bool: return SomeBool() elif t is int: return SomeInteger() elif t is float: return SomeFloat() elif issubclass(t, str): # py.lib uses annotated str subclasses return SomeString() elif t is unicode: return SomeUnicodeString() elif t is types.NoneType: return s_None elif bookkeeper and extregistry.is_registered_type(t): entry = extregistry.lookup_type(t) return entry.compute_annotation_bk(bookkeeper) elif t is type: return SomeType() elif bookkeeper and not hasattr(t, '_freeze_'): classdef = bookkeeper.getuniqueclassdef(t) return SomeInstance(classdef) else: raise AssertionError("annotationoftype(%r)" % (t, ))
def union((obj1, obj2)): result = SomeType() is_type_of1 = getattr(obj1, 'is_type_of', None) is_type_of2 = getattr(obj2, 'is_type_of', None) if obj1.is_immutable_constant() and obj2.is_immutable_constant() and obj1.const == obj2.const: result.const = obj1.const is_type_of = {} if is_type_of1: for v in is_type_of1: is_type_of[v] = True if is_type_of2: for v in is_type_of2: is_type_of[v] = True if is_type_of: result.is_type_of = is_type_of.keys() else: if is_type_of1 and is_type_of1 == is_type_of2: result.is_type_of = is_type_of1 return result
def union((obj1, obj2)): result = SomeType() is_type_of1 = getattr(obj1, 'is_type_of', None) is_type_of2 = getattr(obj2, 'is_type_of', None) if obj1.is_immutable_constant() and obj2.is_immutable_constant( ) and obj1.const == obj2.const: result.const = obj1.const is_type_of = {} if is_type_of1: for v in is_type_of1: is_type_of[v] = True if is_type_of2: for v in is_type_of2: is_type_of[v] = True if is_type_of: result.is_type_of = is_type_of.keys() else: if is_type_of1 and is_type_of1 == is_type_of2: result.is_type_of = is_type_of1 return result
def union((obj1, obj2)): result = SomeType() if obj1.is_immutable_constant() and obj2.is_immutable_constant( ) and obj1.const == obj2.const: result.const = obj1.const return result
def type_SomeObject(annotator, arg): r = SomeType() r.is_type_of = [arg] return r
def union((obj1, obj2)): result = SomeType() if obj1.is_immutable_constant() and obj2.is_immutable_constant() and obj1.const == obj2.const: result.const = obj1.const return result