def unnullify(value, true_function, name, argtype): return ast.If( test=ast.Compare( left=call.sqlite3_value_type(value), ops=[ast.NotEq()], comparators=[load.SQLITE_NULL] ), body=[ast.Assign(targets=[store[name]], value=true_function(value))], orelse=[ast.Assign(targets=[store[name]], value=NONE)], ), None, load[name]
def fail_if_null(value, true_function, name, argtype): return ast.If( test=ast.Compare( left=call.sqlite3_value_type(value), ops=[ast.Eq()], comparators=[load.SQLITE_NULL] ), body=[ ast.Raise( exc=call.TypeError( ast.Str( s=( 'Argument {0!r} is NULL but argument type was {1}.' ' Please change the argument type to optional({1})' ' to accept NULL values.' ).format(SourceVisitor().visit(value), argtype) ) ), cause=None ) ], orelse=[], ), ast.Assign(targets=[store[name]], value=true_function(value)), load[name]