#NEWLINE# def assign_variable_types( variables , local_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , global_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , auto_downcast = 1 , type_converters = converters . default ) : #NEWLINE# #INDENT# incoming_vars = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# incoming_vars . update ( global_dict ) #NEWLINE# incoming_vars . update ( local_dict ) #NEWLINE# variable_specs = [ ] #NEWLINE# errors = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for var in variables : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# example_type = incoming_vars [ var ] #NEWLINE# spec = None #NEWLINE# for factory in type_converters : #NEWLINE# #INDENT# if factory . type_match ( example_type ) : #NEWLINE# #INDENT# spec = factory . type_spec ( var , example_type ) #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# if ( not spec ) : #NEWLINE# #INDENT# raise IndexError #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# variable_specs . append ( spec ) #NEWLINE# #UNINDENT# #UNINDENT# except KeyError : #NEWLINE# #INDENT# errors [ local_dict ] = ( ( ( 'The type and dimensionality specifications' + "for variable '" ) + var ) + "' are missing." ) #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# errors [ var ] = ( ( "Unable to convert variable '" + var ) + "' to a C++ type." ) #NEWLINE# #UNINDENT# #UNINDENT# if errors : #NEWLINE# #INDENT# raise TypeError ( format_error_msg ( errors ) ) #NEWLINE# #UNINDENT# if auto_downcast : #NEWLINE# #INDENT# variable_specs = downcast ( variable_specs ) #NEWLINE# #UNINDENT# return variable_specs