Exemplo n.º 1
0
def wrong_target_is_list():
    match = find_match("for _item_ in ___:\n    pass")
    if match:
        _item_ = match["_item_"].astNode
        if data_state(_item_).was_type('list'):
            explain('The variable <code>{0!s}</code> is a list and should not be placed in the iteration variable slot'
                    ' of the "for" block<br><br><i>(target_is_list)<i></br>.'.format(_item_.id))
            return True
    return False
Exemplo n.º 2
0
def wrong_list_repeated_in_for():
    match = find_match("for _item_ in _item_:\n    pass")
    if match:
        _item_ = match["_item_"].astNode
        if data_state(_item_).was_type('list'):
            explain('The <code>{0!s}</code> variable can only appear once in the "for" block <br><br><i>'
                    '(list_repeat)<i></br>'.format(_item_.id))
            return True
    return False
Exemplo n.º 3
0
def list_initialization_misplaced():
    match = find_match("for ___ in _item_:\n    pass")
    if match:
        _item_ = match["_item_"][0].astNode
        if data_state(_item_).was_type('list') and def_use_error(_item_):
            explain("Initialization of <code>{0!s}</code> is a list but either in the wrong place or redefined"
                    "<br><br><i>(list_init_misplaced)<i></br>".format(_item_.id))
            return True
    return False
Exemplo n.º 4
0
def wrong_iterator_not_list():
    match = find_match("for ___ in _item_:\n    pass")
    if match:
        _item_ = match["_item_"].astNode
        if not data_state(_item_).was_type('list'):
            explain("The variable <code>{0!s}</code> has been set to something that is not a list but is placed in the "
                    "iteration block that must be a list.<br><br><i>(iter_not_list)<i></br>".format(_item_.id))
            return True
    return False
Exemplo n.º 5
0
def wrong_list_repeated_in_for():
    message = 'The <code>{0!s}</code> variable can only appear once in the "for" block.'
    code = "list_repeat"
    tldr = "Duplicate Iteration Variable"
    match = find_match("for _item_ in _item_:\n    pass")
    if match:
        _item_ = match["_item_"].astNode
        if data_state(_item_).was_type('list'):
            return explain_r(message.format(_item_.id), code, label=tldr)
    return False
Exemplo n.º 6
0
def list_initialization_misplaced():
    message = "Initialization of <code>{0!s}</code> is a list but either in the wrong place or redefined"
    code = "list_init_misplaced"
    tldr = "Iterating over Non-list"
    match = find_match("for ___ in _item_:\n    pass")
    if match:
        _item_ = match["_item_"][0].astNode
        if data_state(_item_).was_type('list') and def_use_error(_item_):
            return explain_r(message.format(_item_.id), code, label=tldr)
    return False
Exemplo n.º 7
0
def append_list_wrong_slot():
    matches = find_matches("_target_.append(_item_)")
    if matches:
        for match in matches:
            _item_ = match["_item_"].astNode
            _target_ = match["_target_"].astNode
            if data_state(_item_).was_type('list'):
                explain("You should not append a list (<code>{0!s}</code>) to <code>{1!s}</code>.<br><br><i>"
                        "(app_list_slot)<i></br>".format(_item_.id, _target_.id))
                return True
    return False
Exemplo n.º 8
0
def append_list_wrong_slot():
    matches = find_matches("_target_.append(_item_)")
    if matches:
        for match in matches:
            _item_ = match["_item_"].astNode
            _target_ = match["_target_"].astNode
            if data_state(_item_).was_type('list'):
                explain(
                    "You should not append a list (<code>{0!s}</code>) to <code>{1!s}</code>.<br><br><i>"
                    "(app_list_slot)<i></br>".format(_item_.id, _target_.id))
                return True
    return False
Exemplo n.º 9
0
def missing_iterator_initialization():
    match = find_match("for ___ in _list_:\n    pass")
    if match:
        _list_ = match["_list_"].astNode
        if _list_.id == "___":
            explain("The slot to hold a list in the iteration is empty.<br><br><i>(no_iter_init-blank)<i></br>")
            return True
        elif not data_state(_list_).was_type('list'):
            explain("The variable <code>{0!s}</code> is in the list slot of the iteration but is not a list."
                    "<br><br><i>(no_iter_init)<i></br>".format(_list_.id))
            return True
    return False
Exemplo n.º 10
0
def wrong_target_is_list():
    message = (
        'The variable <code>{0!s}</code> is a list and '
        'should not be placed in the iteration variable slot of the "for" block'
    )
    code = "target_is_list"
    tldr = "Iteration Variable Overwriting List"
    match = find_match("for _item_ in ___:\n    pass")
    if match:
        _item_ = match["_item_"].astNode
        if data_state(_item_).was_type('list'):
            return explain_r(message.format(_item_.id), code, label=tldr)
    return False
Exemplo n.º 11
0
def wrong_iterator_not_list():
    message = (
        "The variable <code>{0!s}</code> has been set to something that is not a list but is placed "
        "in the iteration block that must be a list.")
    code = "iter_not_list"
    tldr = "Iteration List is not list"

    match = find_match("for ___ in _item_:\n    pass")
    if match:
        _item_ = match["_item_"].astNode
        if not data_state(_item_).was_type('list'):
            return explain_r(message.format(_item_.id), code, label=tldr)
    return False
Exemplo n.º 12
0
def wrong_not_append_to_list():
    matches = find_matches("for ___ in ___:\n" "    __expr__")
    for match in matches:
        __expr__ = match["__expr__"]
        submatches = __expr__.find_matches("_target_.append(___)")
        for submatch in submatches:
            _target_ = submatch["_target_"]
            if not data_state(_target_).was_type('list'):
                explain(
                    "Values can only be appended to a list. The variable <code>{0!s}</code> is either "
                    "not initialized, not initialized correctly, or is confused with another variable."
                    "<br><br><i>(app_not_list)<i></br>".format(_target_))
                return True
    return False
Exemplo n.º 13
0
def append_list_wrong_slot():
    message = "You should not append a list (<code>{0!s}</code>) to <code>{1!s}</code>."
    code = "app_list_slot"
    tldr = "Appending List Error"
    matches = find_matches("_target_.append(_item_)")
    if matches:
        for match in matches:
            _item_ = match["_item_"].astNode
            _target_ = match["_target_"].astNode
            if data_state(_item_).was_type('list'):
                return explain_r(message.format(_item_.id, _target_.id),
                                 code,
                                 label=tldr)
    return False
Exemplo n.º 14
0
def wrong_not_append_to_list():
    matches = find_matches("for ___ in ___:\n"
                           "    __expr__")
    for match in matches:
        __expr__ = match["__expr__"]
        submatches = __expr__.find_matches("_target_.append(___)")
        for submatch in submatches:
            _target_ = submatch["_target_"]
            if not data_state(_target_).was_type('list'):
                explain("Values can only be appended to a list. The variable <code>{0!s}</code> is either "
                        "not initialized, not initialized correctly, or is confused with another variable."
                        "<br><br><i>(app_not_list)<i></br>".format(_target_))
                return True
    return False
Exemplo n.º 15
0
def wrong_not_append_to_list():
    message = (
        "Values can only be appended to a list. The variable <code>{0!s}</code> is either not initialized, "
        "not initialized correctly, or is confused with another variable.")
    code = "app_not_list"
    tldr = "Not Appending to List"
    matches = find_matches("for ___ in ___:\n" "    __expr__")
    for match in matches:
        __expr__ = match["__expr__"]
        submatches = __expr__.find_matches("_target_.append(___)")
        for submatch in submatches:
            _target_ = submatch["_target_"]
            if not data_state(_target_).was_type('list'):
                return explain_r(message.format(_target_), code, label=tldr)
    return False
Exemplo n.º 16
0
def missing_iterator_initialization():
    message1 = "The slot to hold a list in the iteration is empty."
    code1 = "no_iter_init-blank"
    tldr1 = "Iteration Variable is Blank"

    message2 = "The variable <code>{0!s}</code> is in the list slot of the iteration but is not a list."
    code2 = "no_iter_init"
    tldr2 = "Iteration Variable is Not a List"

    match = find_match("for ___ in _list_:\n    pass")
    if match:
        _list_ = match["_list_"].astNode
        if _list_.id == "___":
            return explain_r(message1, code1, label=tldr1)
        elif not data_state(_list_).was_type('list'):
            return explain_r(message2.format(_list_.id), code2, label=tldr2)
    return False
Exemplo n.º 17
0
def histogram_argument_not_list():
    """

    Name: histogram_argument_not_list
    Pattern:
       plt.hist(<argument>)
    Where type(<argument>) is not "list"

    Feedback: Making a histogram requires a list; <argument> is not a list.


    Returns:
    """
    matches = find_matches("plt.hist(_argument_)")
    if matches:
        for match in matches:
            _argument_ = match["_argument_"].astNode
            if not data_state(_argument_).was_type('list'):
                explain("Making a histogram requires a list; <code>{0!s}</code> is not a list.<br><br><i>"
                        "(hist_arg_not_list)<i></br>".format(_argument_.id))
                return True
    return False
Exemplo n.º 18
0
def histogram_argument_not_list():
    """

    Name: histogram_argument_not_list
    Pattern:
       plt.hist(<argument>)
    Where type(<argument>) is not "list"

    Feedback: Making a histogram requires a list; <argument> is not a list.


    Returns:
    """
    matches = find_matches("plt.hist(_argument_)")
    if matches:
        for match in matches:
            _argument_ = match["_argument_"].astNode
            if not data_state(_argument_).was_type('list'):
                explain(
                    "Making a histogram requires a list; <code>{0!s}</code> is not a list.<br><br><i>"
                    "(hist_arg_not_list)<i></br>".format(_argument_.id))
                return True
    return False