Esempio n. 1
0
def create_set_unreferenced_var_check(state):
    if ENABLE_CODING_ADVICES:
        attribute = core_language_copy.create_attribute(
            "type_store", "set_check_unreferenced_vars")
        call_ = functions_copy.create_call_expression(
            attribute, [core_language_copy.create_Name(str(state))])

        return call_
    else:
        return []
Esempio n. 2
0
def create_add_stored_type(owner_var, index, value, lineno, col_offset):
    comment = create_src_comment("Storing an element on a container", lineno)
    localization = create_localization(lineno, col_offset)

    add_type_func = core_language_copy.create_attribute(
        owner_var, 'add_key_and_value_type')
    param_tuple = ast.Tuple()
    param_tuple.elts = [index, value]
    set_type_of_member_call = functions_copy.create_call_expression(
        add_type_func, [localization, param_tuple])

    return flatten_lists(comment, set_type_of_member_call)
Esempio n. 3
0
def create_add_alias(alias_name, var_name, lineno, col_offset):
    get_type_of_comment = create_src_comment("Adding an alias")
    get_type_of_method = core_language_copy.create_attribute(
        default_module_type_store_var_name,
        "add_alias",
        line=lineno,
        column=col_offset)

    get_type_of_call = functions_copy.create_call_expression(
        get_type_of_method, [alias_name, var_name])

    return flatten_lists(get_type_of_comment, get_type_of_call)
Esempio n. 4
0
def create_unsupported_feature_call(localization, feature_name, feature_desc,
                                    lineno, col_offset):
    """
    Creates AST nodes to call to the unsupported_python_feature function
    """
    unsupported_feature_func = core_language_copy.create_Name(
        'unsupported_python_feature', line=lineno, column=col_offset)
    unsupported_feature = core_language_copy.create_str(feature_name)
    unsupported_description = core_language_copy.create_str(feature_desc)
    return functions_copy.create_call_expression(
        unsupported_feature_func,
        [localization, unsupported_feature, unsupported_description])
Esempio n. 5
0
def create_store_return_from_function(lineno, col_offset):
    set_type_of_comment = create_src_comment("Storing return type", lineno)
    set_type_of_method = core_language_copy.create_attribute(
        default_module_type_store_var_name,
        "store_return_type_of_current_context")

    return_var_name = core_language_copy.create_Name(
        default_function_ret_var_name)
    set_type_of_call = functions_copy.create_call_expression(
        set_type_of_method, [return_var_name])

    return flatten_lists(set_type_of_comment, set_type_of_call)
Esempio n. 6
0
def create_set_type_of(var_name, new_value, lineno, col_offset):
    set_type_of_comment = create_src_comment("Type assignment", lineno)
    set_type_of_method = core_language_copy.create_attribute(
        default_module_type_store_var_name, "set_type_of")

    localization = create_localization(lineno, col_offset)

    set_type_of_call = functions_copy.create_call_expression(
        set_type_of_method, [
            localization,
            core_language_copy.create_str(var_name, lineno, col_offset),
            new_value
        ])

    return flatten_lists(set_type_of_comment, set_type_of_call)
Esempio n. 7
0
def create_set_type_of_member(owner_var, member_name, value, lineno,
                              col_offset):
    comment = create_src_comment(
        "Setting the type of the member '{0}' of a type".format(member_name),
        lineno)
    localization = create_localization(lineno, col_offset)
    # TODO: Remove?
    # set_type_of_member_func = core_language_copy.create_Name('set_type_of_member')
    # set_type_of_member_call = functions_copy.create_call_expression(set_type_of_member_func, [localization, onwer_var,
    #                                                                           core_language_copy.create_str(
    #                                                                               member_name), value])

    set_type_of_member_func = core_language_copy.create_attribute(
        owner_var, 'set_type_of_member')
    set_type_of_member_call = functions_copy.create_call_expression(
        set_type_of_member_func,
        [localization,
         core_language_copy.create_str(member_name), value])

    return flatten_lists(comment, set_type_of_member_call)