<s> """<STR_LIT>""" <EOL> import sys , types , inspect , weakref <EOL> from pypy . objspace . flow . model import Constant <EOL> from pypy . annotation . model import SomeString , SomeChar , SomeFloat , SomePtr , unionof , SomeInstance , SomeDict , SomeBuiltin , SomePBC , SomeInteger , SomeOOInstance , SomeOOObject , TLS , SomeAddress , SomeUnicodeCodePoint , SomeOOStaticMeth , s_None , s_ImpossibleValue , SomeLLADTMeth , SomeBool , SomeTuple , SomeOOClass , SomeImpossibleValue , SomeUnicodeString , SomeList , SomeObject , HarmlesslyBlocked , SomeWeakRef , lltype_to_annotation <EOL> from pypy . annotation . classdef import InstanceSource , ClassDef <EOL> from pypy . annotation . listdef import ListDef , ListItem <EOL> from pypy . annotation . dictdef import DictDef <EOL> from pypy . annotation import description <EOL> from pypy . annotation . signature import annotationoftype <EOL> from pypy . interpreter . argument import ArgumentsForTranslation <EOL> from pypy . rlib . objectmodel import r_dict , Symbolic <EOL> from pypy . tool . algo . unionfind import UnionFind <EOL> from pypy . rpython . lltypesystem import lltype , llmemory <EOL> from pypy . rpython . ootypesystem import ootype <EOL> from pypy . rpython import extregistry <EOL> class Stats : <EOL> def __init__ ( self , bookkeeper ) : <EOL> self . bookkeeper = bookkeeper <EOL> self . classify = { } <EOL> def count ( self , category , * args ) : <EOL> for_category = self . classify . setdefault ( category , { } ) <EOL> classifier = getattr ( self , '<STR_LIT>' % category , self . consider_generic ) <EOL> outcome = classifier ( * args ) <EOL> for_category [ self . bookkeeper . position_key ] = outcome <EOL> def indexrepr ( self , idx ) : <EOL> if idx . is_constant ( ) : <EOL> if idx . const is None : <EOL> return '<STR_LIT>' <EOL> if isinstance ( idx , SomeInteger ) : <EOL> if idx . const >= <NUM_LIT:0> : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return '<STR_LIT>' <EOL> return idx . const <EOL> else : <EOL> if isinstance ( idx , SomeInteger ) : <EOL> if idx . nonneg : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return self . typerepr ( idx ) <EOL> def steprepr ( self , stp ) : <EOL> if stp . is_constant ( ) : <EOL> if stp . const in ( <NUM_LIT:1> , None ) : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return '<STR_LIT>' % stp . const <EOL> else : <EOL> return '<STR_LIT>' % self . typerepr ( stp ) <EOL> def consider_generic ( self , * args ) : <EOL> return tuple ( [ self . typerepr ( x ) for x in args ] ) <EOL> def consider_list_list_eq ( self , obj1 , obj2 ) : <EOL> return obj1 , obj2 <EOL> def consider_contains ( self , seq ) : <EOL> return seq <EOL> def consider_non_int_eq ( self , obj1 , obj2 ) : <EOL> if obj1 . knowntype == obj2 . knowntype == list : <EOL> self . count ( "<STR_LIT>" , obj1 , obj2 ) <EOL> return self . typerepr ( obj1 ) , self . typerepr ( obj2 ) <EOL> def consider_non_int_comp ( self , obj1 , obj2 ) : <EOL> return self . typerepr ( obj1 ) , self . typerepr ( obj2 ) <EOL> def typerepr ( self , obj ) : <EOL> if isinstance ( obj , SomeInstance ) : <EOL> return obj . classdef . name <EOL> else : <EOL> return obj . knowntype . __name__ <EOL> def consider_tuple_iter ( self , tup ) : <EOL> ctxt = "<STR_LIT>" % sys . _getframe ( <NUM_LIT:4> ) . f_code . co_name <EOL> if tup . is_constant ( ) : <EOL> return ctxt , tup . const <EOL> else : <EOL> return ctxt , tuple ( [ self . typerepr ( x ) for x in tup . items ] ) <EOL> def consider_tuple_random_getitem ( self , tup ) : <EOL> return tuple ( [ self . typerepr ( x ) for x in tup . items ] ) <EOL> def consider_list_index ( self ) : <EOL> return '<STR_LIT:!>' <EOL> def consider_list_getitem ( self , idx ) : <EOL> return self . indexrepr ( idx ) <EOL> def consider_list_setitem ( self , idx ) : <EOL> return self . indexrepr ( idx ) <EOL> def consider_list_delitem ( self , idx ) : <EOL> return self . indexrepr ( idx ) <EOL> def consider_str_join ( self , s ) : <EOL> if s . is_constant ( ) : <EOL> return repr ( s . const ) <EOL> else : <EOL> return "<STR_LIT>" <EOL> def consider_str_getitem ( self , idx ) : <EOL> return self . indexrepr ( idx ) <EOL> def consider_strformat ( self , str , args ) : <EOL> if str . is_constant ( ) : <EOL> s = repr ( str . const ) <EOL> else : <EOL> s = "<STR_LIT>" <EOL> if isinstance ( args , SomeTuple ) : <EOL> return ( s , tuple ( [ self . typerepr ( x ) for x in args . items ] ) ) <EOL> else : <EOL> return ( s , self . typerepr ( args ) ) <EOL> def consider_dict_getitem ( self , dic ) : <EOL> return dic <EOL> def consider_dict_setitem ( self , dic ) : <EOL> return dic <EOL> def consider_dict_delitem ( self , dic ) : <EOL> return dic <EOL> class Bookkeeper : <EOL> """<STR_LIT>""" <EOL> def __setstate__ ( self , dic ) : <EOL> self . __dict__ . update ( dic ) <EOL> delayed_imports ( ) <EOL> def __init__ ( self , annotator ) : <EOL> self . annotator = annotator <EOL> self . policy = annotator . policy <EOL> self . descs = { } <EOL> self . methoddescs = { } <EOL> self . classdefs = [ ] <EOL> self . pbctypes = { } <EOL> self . seen_mutable = { } <EOL> self . listdefs = { } <EOL> self . dictdefs = { } <EOL> self . immutable_cache = { } <EOL> self . classpbc_attr_families = { } <EOL> self . frozenpbc_attr_families = UnionFind ( description . FrozenAttrFamily ) <EOL> self . pbc_maximal_call_families = UnionFind ( description . CallFamily ) <EOL> self . emulated_pbc_calls = { } <EOL> self . all_specializations = { } <EOL> self . pending_specializations = [ ] <EOL> self . external_class_cache = { } <EOL> self . needs_generic_instantiate = { } <EOL> self . stats = Stats ( self ) <EOL> self . _someobject_coming_from = { } <EOL> delayed_imports ( ) <EOL> def count ( self , category , * args ) : <EOL> self . stats . count ( category , * args ) <EOL> def enter ( self , position_key ) : <EOL> """<STR_LIT>""" <EOL> assert not hasattr ( self , '<STR_LIT>' ) , "<STR_LIT>" <EOL> self . position_key = position_key <EOL> TLS . bookkeeper = self <EOL> def leave ( self ) : <EOL> """<STR_LIT>""" <EOL> del TLS . bookkeeper <EOL> del self . position_key <EOL> def compute_at_fixpoint ( self ) : <EOL> self . enter ( None ) <EOL> try : <EOL> def call_sites ( ) : <EOL> newblocks = self . annotator . added_blocks <EOL> if newblocks is None : <EOL> newblocks = self . annotator . annotated <EOL> binding = self . annotator . binding <EOL> for block in newblocks : <EOL> for op in block . operations : <EOL> if op . opname in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> yield op <EOL> if binding ( op . result , None ) is None : <EOL> break <EOL> for call_op in call_sites ( ) : <EOL> self . consider_call_site ( call_op ) <EOL> for pbc , args_s in self . emulated_pbc_calls . itervalues ( ) : <EOL> self . consider_call_site_for_pbc ( pbc , '<STR_LIT>' , <EOL> args_s , s_ImpossibleValue ) <EOL> self . emulated_pbc_calls = { } <EOL> finally : <EOL> self . leave ( ) <EOL> seen = set ( ) <EOL> def check_no_flags ( s_value_or_def ) : <EOL> if isinstance ( s_value_or_def , SomeInstance ) : <EOL> assert not s_value_or_def . flags , "<STR_LIT>" <EOL> check_no_flags ( s_value_or_def . classdef ) <EOL> elif isinstance ( s_value_or_def , SomeList ) : <EOL> check_no_flags ( s_value_or_def . listdef . listitem ) <EOL> elif isinstance ( s_value_or_def , SomeDict ) : <EOL> check_no_flags ( s_value_or_def . dictdef . dictkey ) <EOL> check_no_flags ( s_value_or_def . dictdef . dictvalue ) <EOL> elif isinstance ( s_value_or_def , SomeTuple ) : <EOL> for s_item in s_value_or_def . items : <EOL> check_no_flags ( s_item ) <EOL> elif isinstance ( s_value_or_def , ClassDef ) : <EOL> if s_value_or_def in seen : <EOL> return <EOL> seen . add ( s_value_or_def ) <EOL> for attr in s_value_or_def . attrs . values ( ) : <EOL> s_attr = attr . s_value <EOL> check_no_flags ( s_attr ) <EOL> elif isinstance ( s_value_or_def , ListItem ) : <EOL> if s_value_or_def in seen : <EOL> return <EOL> seen . add ( s_value_or_def ) <EOL> check_no_flags ( s_value_or_def . s_value ) <EOL> for clsdef in self . classdefs : <EOL> check_no_flags ( clsdef ) <EOL> def consider_call_site ( self , call_op ) : <EOL> binding = self . annotator . binding <EOL> s_callable = binding ( call_op . args [ <NUM_LIT:0> ] ) <EOL> args_s = [ binding ( arg ) for arg in call_op . args [ <NUM_LIT:1> : ] ] <EOL> if isinstance ( s_callable , SomeLLADTMeth ) : <EOL> adtmeth = s_callable <EOL> s_callable = self . immutablevalue ( adtmeth . func ) <EOL> args_s = [ lltype_to_annotation ( adtmeth . ll_ptrtype ) ] + args_s <EOL> if isinstance ( s_callable , SomePBC ) : <EOL> s_result = binding ( call_op . result , s_ImpossibleValue ) <EOL> self . consider_call_site_for_pbc ( s_callable , <EOL> call_op . opname , <EOL> args_s , s_result ) <EOL> def consider_call_site_for_pbc ( self , s_callable , opname , args_s , s_result ) : <EOL> descs = s_callable . descriptions . keys ( ) <EOL> if not descs : <EOL> return <EOL> family = descs [ <NUM_LIT:0> ] . getcallfamily ( ) <EOL> args = self . build_args ( opname , args_s ) <EOL> s_callable . getKind ( ) . consider_call_site ( self , family , descs , args , <EOL> s_result ) <EOL> def getuniqueclassdef ( self , cls ) : <EOL> """<STR_LIT>""" <EOL> if cls is object : <EOL> return None <EOL> desc = self . getdesc ( cls ) <EOL> return desc . getuniqueclassdef ( ) <EOL> def getlistdef ( self , ** flags ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> listdef = self . listdefs [ self . position_key ] <EOL> except KeyError : <EOL> listdef = self . listdefs [ self . position_key ] = ListDef ( self ) <EOL> listdef . listitem . __dict__ . update ( flags ) <EOL> return listdef <EOL> def newlist ( self , * s_values , ** flags ) : <EOL> """<STR_LIT>""" <EOL> listdef = self . getlistdef ( ** flags ) <EOL> for s_value in s_values : <EOL> listdef . generalize ( s_value ) <EOL> return SomeList ( listdef ) <EOL> def getdictdef ( self , is_r_dict = False ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> dictdef = self . dictdefs [ self . position_key ] <EOL> except KeyError : <EOL> dictdef = DictDef ( self , is_r_dict = is_r_dict ) <EOL> self . dictdefs [ self . position_key ] = dictdef <EOL> return dictdef <EOL> def newdict ( self ) : <EOL> """<STR_LIT>""" <EOL> return SomeDict ( self . getdictdef ( ) ) <EOL> def immutableconstant ( self , const ) : <EOL> return self . immutablevalue ( const . value ) <EOL> def immutablevalue ( self , x , need_const = True ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( x , '<STR_LIT>' ) and x . im_self is None : <EOL> x = x . im_func <EOL> assert not hasattr ( x , '<STR_LIT>' ) <EOL> if x is sys : <EOL> return SomeObject ( ) <EOL> tp = type ( x ) <EOL> if issubclass ( tp , Symbolic ) : <EOL> result = x . annotation ( ) <EOL> result . const_box = Constant ( x ) <EOL> return result <EOL> if tp is bool : <EOL> result = SomeBool ( ) <EOL> elif tp is int : <EOL> result = SomeInteger ( nonneg = x >= <NUM_LIT:0> ) <EOL> elif tp is long and <NUM_LIT:0> <= x <= ( sys . maxint * <NUM_LIT:2> + <NUM_LIT:1> ) : <EOL> result = SomeInteger ( unsigned = True ) <EOL> elif issubclass ( tp , str ) : <EOL> if len ( x ) == <NUM_LIT:1> : <EOL> result = SomeChar ( ) <EOL> else : <EOL> result = SomeString ( ) <EOL> elif tp is unicode : <EOL> if len ( x ) == <NUM_LIT:1> : <EOL> result = SomeUnicodeCodePoint ( ) <EOL> else : <EOL> result = SomeUnicodeString ( ) <EOL> elif tp is tuple : <EOL> result = SomeTuple ( items = [ self . immutablevalue ( e , need_const ) for e in x ] ) <EOL> elif tp is float : <EOL> result = SomeFloat ( ) <EOL> elif tp is list : <EOL> if need_const : <EOL> key = Constant ( x ) <EOL> try : <EOL> return self . immutable_cache [ key ] <EOL> except KeyError : <EOL> result = SomeList ( ListDef ( self , s_ImpossibleValue ) ) <EOL> self . immutable_cache [ key ] = result <EOL> for e in x : <EOL> result . listdef . generalize ( self . immutablevalue ( e ) ) <EOL> result . const_box = key <EOL> return result <EOL> else : <EOL> listdef = ListDef ( self , s_ImpossibleValue ) <EOL> for e in x : <EOL> listdef . generalize ( self . immutablevalue ( e , False ) ) <EOL> result = SomeList ( listdef ) <EOL> elif tp is dict or tp is r_dict : <EOL> if need_const : <EOL> key = Constant ( x ) <EOL> try : <EOL> return self . immutable_cache [ key ] <EOL> except KeyError : <EOL> result = SomeDict ( DictDef ( self , <EOL> s_ImpossibleValue , <EOL> s_ImpossibleValue , <EOL> is_r_dict = tp is r_dict ) ) <EOL> self . immutable_cache [ key ] = result <EOL> if tp is r_dict : <EOL> s_eqfn = self . immutablevalue ( x . key_eq ) <EOL> s_hashfn = self . immutablevalue ( x . key_hash ) <EOL> result . dictdef . dictkey . update_rdict_annotations ( s_eqfn , <EOL> s_hashfn ) <EOL> seen_elements = <NUM_LIT:0> <EOL> while seen_elements != len ( x ) : <EOL> items = x . items ( ) <EOL> for ek , ev in items : <EOL> result . dictdef . generalize_key ( self . immutablevalue ( ek ) ) <EOL> result . dictdef . generalize_value ( self . immutablevalue ( ev ) ) <EOL> result . dictdef . seen_prebuilt_key ( ek ) <EOL> seen_elements = len ( items ) <EOL> result . const_box = key <EOL> return result <EOL> else : <EOL> dictdef = DictDef ( self , <EOL> s_ImpossibleValue , <EOL> s_ImpossibleValue , <EOL> is_r_dict = tp is r_dict ) <EOL> if tp is r_dict : <EOL> s_eqfn = self . immutablevalue ( x . key_eq ) <EOL> s_hashfn = self . immutablevalue ( x . key_hash ) <EOL> dictdef . dictkey . update_rdict_annotations ( s_eqfn , <EOL> s_hashfn ) <EOL> for ek , ev in x . iteritems ( ) : <EOL> dictdef . generalize_key ( self . immutablevalue ( ek , False ) ) <EOL> dictdef . generalize_value ( self . immutablevalue ( ev , False ) ) <EOL> dictdef . seen_prebuilt_key ( ek ) <EOL> result = SomeDict ( dictdef ) <EOL> elif tp is weakref . ReferenceType : <EOL> x1 = x ( ) <EOL> if x1 is None : <EOL> result = SomeWeakRef ( None ) <EOL> else : <EOL> s1 = self . immutablevalue ( x1 ) <EOL> assert isinstance ( s1 , SomeInstance ) <EOL> result = SomeWeakRef ( s1 . classdef ) <EOL> elif ishashable ( x ) and x in BUILTIN_ANALYZERS : <EOL> _module = getattr ( x , "<STR_LIT>" , "<STR_LIT>" ) <EOL> result = SomeBuiltin ( BUILTIN_ANALYZERS [ x ] , methodname = "<STR_LIT>" % ( _module , x . __name__ ) ) <EOL> elif extregistry . is_registered ( x , self . policy ) : <EOL> entry = extregistry . lookup ( x , self . policy ) <EOL> result = entry . compute_annotation_bk ( self ) <EOL> elif isinstance ( x , lltype . _ptr ) : <EOL> result = SomePtr ( lltype . typeOf ( x ) ) <EOL> elif isinstance ( x , llmemory . fakeaddress ) : <EOL> result = SomeAddress ( is_null = not x ) <EOL> elif isinstance ( x , ootype . _static_meth ) : <EOL> result = SomeOOStaticMeth ( ootype . typeOf ( x ) ) <EOL> elif isinstance ( x , ootype . _class ) : <EOL> result = SomeOOClass ( x . _INSTANCE ) <EOL> elif isinstance ( x , ootype . instance_impl ) : <EOL> result = SomeOOInstance ( ootype . typeOf ( x ) ) <EOL> elif isinstance ( x , ( ootype . _record , ootype . _string ) ) : <EOL> result = SomeOOInstance ( ootype . typeOf ( x ) ) <EOL> elif isinstance ( x , ( ootype . _object ) ) : <EOL> result = SomeOOObject ( ) <EOL> elif callable ( x ) : <EOL> if hasattr ( x , '<STR_LIT>' ) and hasattr ( x , '<STR_LIT>' ) : <EOL> s_self = self . immutablevalue ( x . im_self , need_const ) <EOL> result = s_self . find_method ( x . im_func . __name__ ) <EOL> elif hasattr ( x , '<STR_LIT>' ) and x . __self__ is not None : <EOL> s_self = self . immutablevalue ( x . __self__ , need_const ) <EOL> result = s_self . find_method ( x . __name__ ) <EOL> if result is None : <EOL> result = SomeObject ( ) <EOL> else : <EOL> result = None <EOL> if result is None : <EOL> if ( self . annotator . policy . allow_someobjects <EOL> and getattr ( x , '<STR_LIT>' , None ) == '<STR_LIT>' <EOL> and tp not in ( types . FunctionType , types . MethodType ) ) : <EOL> result = SomeObject ( ) <EOL> result . knowntype = tp <EOL> else : <EOL> result = SomePBC ( [ self . getdesc ( x ) ] ) <EOL> elif hasattr ( x , '<STR_LIT>' ) and x . _freeze_ ( ) : <EOL> result = SomePBC ( [ self . getdesc ( x ) ] ) <EOL> elif hasattr ( x , '<STR_LIT>' ) and x . __class__ . __module__ != '<STR_LIT>' : <EOL> self . see_mutable ( x ) <EOL> result = SomeInstance ( self . getuniqueclassdef ( x . __class__ ) ) <EOL> elif x is None : <EOL> return s_None <EOL> else : <EOL> result = SomeObject ( ) <EOL> if need_const : <EOL> result . const = x <EOL> return result <EOL> def getdesc ( self , pyobj ) : <EOL> try : <EOL> return self . descs [ pyobj ] <EOL> except KeyError : <EOL> if isinstance ( pyobj , types . FunctionType ) : <EOL> result = description . FunctionDesc ( self , pyobj ) <EOL> elif isinstance ( pyobj , ( type , types . ClassType ) ) : <EOL> if pyobj is object : <EOL> raise Exception , "<STR_LIT>" <EOL> if pyobj . __module__ == '<STR_LIT>' : <EOL> result = self . getfrozen ( pyobj ) <EOL> else : <EOL> result = description . ClassDesc ( self , pyobj ) <EOL> elif isinstance ( pyobj , types . MethodType ) : <EOL> if pyobj . im_self is None : <EOL> return self . getdesc ( pyobj . im_func ) <EOL> elif ( hasattr ( pyobj . im_self , '<STR_LIT>' ) and <EOL> pyobj . im_self . _freeze_ ( ) ) : <EOL> result = description . MethodOfFrozenDesc ( self , <EOL> self . getdesc ( pyobj . im_func ) , <EOL> self . getdesc ( pyobj . im_self ) ) <EOL> else : <EOL> origincls , name = origin_of_meth ( pyobj ) <EOL> self . see_mutable ( pyobj . im_self ) <EOL> assert pyobj == getattr ( pyobj . im_self , name ) , ( <EOL> "<STR_LIT>" % ( pyobj , pyobj . im_self , name ) ) <EOL> classdef = self . getuniqueclassdef ( pyobj . im_class ) <EOL> classdef . find_attribute ( name ) <EOL> result = self . getmethoddesc ( <EOL> self . getdesc ( pyobj . im_func ) , <EOL> self . getuniqueclassdef ( origincls ) , <EOL> classdef , <EOL> name ) <EOL> else : <EOL> try : <EOL> assert pyobj . _freeze_ ( ) <EOL> except AttributeError : <EOL> raise Exception ( "<STR_LIT>" % ( <EOL> pyobj , ) ) <EOL> result = self . getfrozen ( pyobj ) <EOL> self . descs [ pyobj ] = result <EOL> return result <EOL> def have_seen ( self , x ) : <EOL> if x in self . descs : <EOL> return True <EOL> elif x in self . seen_mutable : <EOL> return True <EOL> else : <EOL> return False <EOL> def getfrozen ( self , pyobj ) : <EOL> result = description . FrozenDesc ( self , pyobj ) <EOL> cls = result . knowntype <EOL> if cls not in self . pbctypes : <EOL> self . pbctypes [ cls ] = True <EOL> return result <EOL> def getmethoddesc ( self , funcdesc , originclassdef , selfclassdef , name , <EOL> flags = { } ) : <EOL> flagskey = flags . items ( ) <EOL> flagskey . sort ( ) <EOL> key = funcdesc , originclassdef , selfclassdef , name , tuple ( flagskey ) <EOL> try : <EOL> return self . methoddescs [ key ] <EOL> except KeyError : <EOL> result = description . MethodDesc ( self , funcdesc , originclassdef , <EOL> selfclassdef , name , flags ) <EOL> self . methoddescs [ key ] = result <EOL> return result <EOL> def see_mutable ( self , x ) : <EOL> if x in self . seen_mutable : <EOL> return <EOL> clsdef = self . getuniqueclassdef ( x . __class__ ) <EOL> self . seen_mutable [ x ] = True <EOL> self . event ( '<STR_LIT>' , x ) <EOL> source = InstanceSource ( self , x ) <EOL> for attr in source . all_instance_attributes ( ) : <EOL> clsdef . add_source_for_attribute ( attr , source ) <EOL> def valueoftype ( self , t ) : <EOL> return annotationoftype ( t , self ) <EOL> def get_classpbc_attr_families ( self , attrname ) : <EOL> """<STR_LIT>""" <EOL> map = self . classpbc_attr_families <EOL> try : <EOL> access_sets = map [ attrname ] <EOL> except KeyError : <EOL> access_sets = map [ attrname ] = UnionFind ( description . ClassAttrFamily ) <EOL> return access_sets <EOL> def pbc_getattr ( self , pbc , s_attr ) : <EOL> assert s_attr . is_constant ( ) <EOL> attr = s_attr . const <EOL> descs = pbc . descriptions . keys ( ) <EOL> if not descs : <EOL> return s_ImpossibleValue <EOL> first = descs [ <NUM_LIT:0> ] <EOL> if len ( descs ) == <NUM_LIT:1> : <EOL> return first . s_read_attribute ( attr ) <EOL> change = first . mergeattrfamilies ( descs [ <NUM_LIT:1> : ] , attr ) <EOL> attrfamily = first . getattrfamily ( attr ) <EOL> position = self . position_key <EOL> attrfamily . read_locations [ position ] = True <EOL> actuals = [ ] <EOL> for desc in descs : <EOL> actuals . append ( desc . s_read_attribute ( attr ) ) <EOL> s_result = unionof ( * actuals ) <EOL> s_oldvalue = attrfamily . get_s_value ( attr ) <EOL> attrfamily . set_s_value ( attr , unionof ( s_result , s_oldvalue ) ) <EOL> if change : <EOL> for position in attrfamily . read_locations : <EOL> self . annotator . reflowfromposition ( position ) <EOL> if isinstance ( s_result , SomeImpossibleValue ) : <EOL> for desc in descs : <EOL> try : <EOL> attrs = desc . read_attribute ( '<STR_LIT>' ) <EOL> except AttributeError : <EOL> continue <EOL> if isinstance ( attrs , Constant ) : <EOL> attrs = attrs . value <EOL> if attr in attrs : <EOL> raise HarmlesslyBlocked ( "<STR_LIT>" ) <EOL> return s_result <EOL> def pbc_call ( self , pbc , args , emulated = None ) : <EOL> """<STR_LIT>""" <EOL> descs = pbc . descriptions . keys ( ) <EOL> if not descs : <EOL> return s_ImpossibleValue <EOL> first = descs [ <NUM_LIT:0> ] <EOL> first . mergecallfamilies ( * descs [ <NUM_LIT:1> : ] ) <EOL> if emulated is None : <EOL> whence = self . position_key <EOL> fn , block , i = self . position_key <EOL> op = block . operations [ i ] <EOL> s_previous_result = self . annotator . binding ( op . result , <EOL> s_ImpossibleValue ) <EOL> else : <EOL> if emulated is True : <EOL> whence = None <EOL> else : <EOL> whence = emulated <EOL> s_previous_result = s_ImpossibleValue <EOL> def schedule ( graph , inputcells ) : <EOL> return self . annotator . recursivecall ( graph , whence , inputcells ) <EOL> results = [ ] <EOL> for desc in descs : <EOL> results . append ( desc . pycall ( schedule , args , s_previous_result ) ) <EOL> s_result = unionof ( * results ) <EOL> return s_result <EOL> def emulate_pbc_call ( self , unique_key , pbc , args_s , replace = [ ] , callback = None ) : <EOL> emulate_enter = not hasattr ( self , '<STR_LIT>' ) <EOL> if emulate_enter : <EOL> self . enter ( None ) <EOL> try : <EOL> emulated_pbc_calls = self . emulated_pbc_calls <EOL> prev = [ unique_key ] <EOL> prev . extend ( replace ) <EOL> for other_key in prev : <EOL> if other_key in emulated_pbc_calls : <EOL> del emulated_pbc_calls [ other_key ] <EOL> emulated_pbc_calls [ unique_key ] = pbc , args_s <EOL> args = self . build_args ( "<STR_LIT>" , args_s ) <EOL> if callback is None : <EOL> emulated = True <EOL> else : <EOL> emulated = callback <EOL> return self . pbc_call ( pbc , args , emulated = emulated ) <EOL> finally : <EOL> if emulate_enter : <EOL> self . leave ( ) <EOL> def build_args ( self , op , args_s ) : <EOL> space = RPythonCallsSpace ( ) <EOL> if op == "<STR_LIT>" : <EOL> return ArgumentsForTranslation ( space , list ( args_s ) ) <EOL> elif op == "<STR_LIT>" : <EOL> return ArgumentsForTranslation . fromshape ( <EOL> space , args_s [ <NUM_LIT:0> ] . const , <EOL> list ( args_s [ <NUM_LIT:1> : ] ) ) <EOL> def ondegenerated ( self , what , s_value , where = None , called_from_graph = None ) : <EOL> self . annotator . ondegenerated ( what , s_value , where = where , <EOL> called_from_graph = called_from_graph ) <EOL> def whereami ( self ) : <EOL> return self . annotator . whereami ( self . position_key ) <EOL> def event ( self , what , x ) : <EOL> return self . annotator . policy . event ( self , what , x ) <EOL> def warning ( self , msg ) : <EOL> return self . annotator . warning ( msg ) <EOL> def origin_of_meth ( boundmeth ) : <EOL> func = boundmeth . im_func <EOL> candname = func . func_name <EOL> for cls in inspect . getmro ( boundmeth . im_class ) : <EOL> dict = cls . __dict__ <EOL> if dict . get ( candname ) is func : <EOL> return cls , candname <EOL> for name , value in dict . iteritems ( ) : <EOL> if value is func : <EOL> return cls , name <EOL> raise Exception , "<STR_LIT>" % ( boundmeth , ) <EOL> def ishashable ( x ) : <EOL> try : <EOL> hash ( x ) <EOL> except TypeError : <EOL> return False <EOL> else : <EOL> return True <EOL> class RPythonCallsSpace : <EOL> """<STR_LIT>""" <EOL> w_tuple = SomeTuple <EOL> def newtuple ( self , items_s ) : <EOL> if items_s == [ Ellipsis ] : <EOL> res = SomeObject ( ) <EOL> res . from_ellipsis = True <EOL> return res <EOL> else : <EOL> return SomeTuple ( items_s ) <EOL> def newdict ( self ) : <EOL> raise CallPatternTooComplex , "<STR_LIT>" <EOL> def unpackiterable ( self , s_obj , expected_length = None ) : <EOL> if isinstance ( s_obj , SomeTuple ) : <EOL> if ( expected_length is not None and <EOL> expected_length != len ( s_obj . items ) ) : <EOL> raise ValueError <EOL> return list ( s_obj . items ) <EOL> if ( s_obj . __class__ is SomeObject and <EOL> getattr ( s_obj , '<STR_LIT>' , False ) ) : <EOL> return [ Ellipsis ] <EOL> raise CallPatternTooComplex , "<STR_LIT>" <EOL> viewiterable = unpackiterable <EOL> def is_w ( self , one , other ) : <EOL> return one is other <EOL> def type ( self , item ) : <EOL> return type ( item ) <EOL> def is_true ( self , s_tup ) : <EOL> assert isinstance ( s_tup , SomeTuple ) <EOL> return bool ( s_tup . items ) <EOL> class CallPatternTooComplex ( Exception ) : <EOL> pass <EOL> def getbookkeeper ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return TLS . bookkeeper <EOL> except AttributeError : <EOL> return None <EOL> def delayed_imports ( ) : <EOL> global BUILTIN_ANALYZERS <EOL> from pypy . annotation . builtin import BUILTIN_ANALYZERS </s>
