def parse_nni_variable(code):
    """Parse `nni.variable` expression.
    Return the name argument and AST node of annotated expression.
    code: annotation string
    """
    name, call = parse_annotation_function(code, 'variable')

    assert len(call.args) == 1, 'nni.variable contains more than one arguments'
    arg = call.args[0]
    assert type(arg) is ast.Call, 'Value of nni.variable is not a function call'
    assert type(arg.func) is ast.Attribute, 'nni.variable value is not a NNI function'
    assert type(arg.func.value) is ast.Name, 'nni.variable value is not a NNI function'
    assert arg.func.value.id == 'nni', 'nni.variable value is not a NNI function'

    name_str = astor.to_source(name).strip()
    keyword_arg = ast.keyword(arg='name', value=ast.Str(s=name_str))
    arg.keywords.append(keyword_arg)
    if arg.func.attr == 'choice':
        convert_args_to_dict(arg)

    return name, arg
def parse_nni_variable ( code ) : name , call = parse_annotation_function ( code , 'variable' ) assert len ( call . args ) == 1 , 'nni.variable contains more than one arguments' arg = call . args [ 0 ] assert type ( arg ) is ast . Call , 'Value of nni.variable is not a function call' assert type ( arg . func ) is ast . Attribute , 'nni.variable value is not a NNI function' assert type ( arg . func . value ) is ast . Name , 'nni.variable value is not a NNI function' assert arg . func . value . id == 'nni' , 'nni.variable value is not a NNI function' name_str = astor . to_source ( name ) . strip ( ) keyword_arg = ast . keyword ( arg = 'name' , value = ast . Str ( s = name_str ) ) arg . keywords . append ( keyword_arg ) if arg . func . attr == 'choice' : convert_args_to_dict ( arg ) return name , arg
Parse `nni.variable` expression.
    Return the name argument and AST node of annotated expression.
    code: annotation string