예제 #1
0
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,))
예제 #2
0
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, ))
예제 #3
0
 def rtyper_makerepr(self, rtyper):
     entry = extregistry.lookup_type(self.knowntype)
     return entry.get_repr(rtyper, self)
예제 #4
0
 def rtyper_makerepr(self, rtyper):
     entry = extregistry.lookup_type(self.knowntype)
     return entry.get_repr(rtyper, self)