<s> import inspect <EOL> from numba import types <EOL> from . typing . typeof import typeof_impl <EOL> from . typing . templates import infer , infer_getattr <EOL> from . targets . imputils import ( <EOL> lower_builtin , lower_getattr , lower_getattr_generic , <EOL> lower_setattr , lower_setattr_generic , lower_cast ) <EOL> from . datamodel import models , register_default as register_model <EOL> from . pythonapi import box , unbox , reflect , NativeValue <EOL> def type_callable ( func ) : <EOL> """<STR_LIT>""" <EOL> from . typing . templates import CallableTemplate , infer , infer_global <EOL> if not callable ( func ) and not isinstance ( func , str ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> try : <EOL> func_name = func . __name__ <EOL> except AttributeError : <EOL> func_name = str ( func ) <EOL> def decorate ( typing_func ) : <EOL> def generic ( self ) : <EOL> return typing_func ( self . context ) <EOL> name = "<STR_LIT>" % ( func_name , ) <EOL> bases = ( CallableTemplate , ) <EOL> class_dict = dict ( key = func , generic = generic ) <EOL> template = type ( name , bases , class_dict ) <EOL> infer ( template ) <EOL> if hasattr ( func , '<STR_LIT>' ) : <EOL> infer_global ( func , types . Function ( template ) ) <EOL> return decorate <EOL> def overload ( func ) : <EOL> """<STR_LIT>""" <EOL> from . typing . templates import make_overload_template , infer_global <EOL> def decorate ( overload_func ) : <EOL> template = make_overload_template ( func , overload_func ) <EOL> infer ( template ) <EOL> if hasattr ( func , '<STR_LIT>' ) : <EOL> infer_global ( func , types . Function ( template ) ) <EOL> return overload_func <EOL> return decorate <EOL> def overload_attribute ( typ , attr ) : <EOL> """<STR_LIT>""" <EOL> from . typing . templates import make_overload_attribute_template <EOL> def decorate ( overload_func ) : <EOL> template = make_overload_attribute_template ( typ , attr , overload_func ) <EOL> infer_getattr ( template ) <EOL> return overload_func <EOL> return decorate <EOL> def overload_method ( typ , attr ) : <EOL> """<STR_LIT>""" <EOL> from . typing . templates import make_overload_method_template <EOL> def decorate ( overload_func ) : <EOL> template = make_overload_method_template ( typ , attr , overload_func ) <EOL> infer_getattr ( template ) <EOL> return overload_func <EOL> return decorate <EOL> def make_attribute_wrapper ( typeclass , struct_attr , python_attr ) : <EOL> """<STR_LIT>""" <EOL> from . typing . templates import AttributeTemplate <EOL> from . datamodel import default_manager <EOL> from . datamodel . models import StructModel <EOL> from . targets . imputils import impl_ret_borrowed <EOL> from . import cgutils <EOL> if not isinstance ( typeclass , type ) or not issubclass ( typeclass , types . Type ) : <EOL> raise TypeError ( "<STR_LIT>" <EOL> % ( typeclass , ) ) <EOL> def get_attr_fe_type ( typ ) : <EOL> """<STR_LIT>""" <EOL> model = default_manager . lookup ( typ ) <EOL> if not isinstance ( model , StructModel ) : <EOL> raise TypeError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( model , ) ) <EOL> return model . get_member_fe_type ( struct_attr ) <EOL> @ infer_getattr <EOL> class StructAttribute ( AttributeTemplate ) : <EOL> key = typeclass <EOL> def generic_resolve ( self , typ , attr ) : <EOL> if attr == python_attr : <EOL> return get_attr_fe_type ( typ ) <EOL> @ lower_getattr ( typeclass , python_attr ) <EOL> def struct_getattr_impl ( context , builder , typ , val ) : <EOL> val = cgutils . create_struct_proxy ( typ ) ( context , builder , value = val ) <EOL> attrty = get_attr_fe_type ( typ ) <EOL> attrval = getattr ( val , struct_attr ) <EOL> return impl_ret_borrowed ( context , builder , attrty , attrval ) </s>
