SylvainDe / DidYouMean-Python

Module to have suggestions in case of errors (NameError, AttributeError, etc).
MIT License
120 stars 15 forks source link

NameError: Add new test case/regexp #20

Open SylvainDe opened 8 years ago

SylvainDe commented 8 years ago

Got add different error message

NameError: free variable 'title' referenced before assignment in enclosing scope

$ python --version Python 3.2.3

SylvainDe commented 8 years ago

Suggestion:

@register_suggestion_for(NameError, re.VARREFBEFOREASSIGN_RE)
def suggest_local_var_ref_before_assign(value, frame, groups):
    """Get the suggestions for local var reference before assign."""
    del value  # unused param
    name, = groups
    objs = get_objects_in_frame(frame).get(name, [])
    for obj, scope in objs:
        # TODO_ENCLOSING: suggest 'nonlocal'
        if scope == 'global':
            return
            yield quote('global ' + name)