Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F811 incorrectly raised for type annotation of imported variable #617

Closed
mick88 opened this issue Mar 15, 2021 · 3 comments · Fixed by #619
Closed

F811 incorrectly raised for type annotation of imported variable #617

mick88 opened this issue Mar 15, 2021 · 3 comments · Fixed by #619

Comments

@mick88
Copy link

mick88 commented Mar 15, 2021

The following piece of code raises F811 error in pyflakes 2.3.0:

        from django.core.files.storage import default_storage
        default_storage: Storage
        file_path = os.path.join(constants.FILE_FIELD_UPLOAD_DIR_NAME, value.name)
        value = default_storage.save(file_path, value)

I am using pyflakes with flake8 and getting this output:

F811 redefinition of unused 'default_storage' from line 124
        default_storage: Storage
        ^
1     F811 redefinition of unused 'default_storage' from line 124

the code works correctly and default_storage: Storage does not redefine the variable, and default_storage is used two lines below.

@asottile
Copy link
Member

can confirm -- looks like a slight regression in #535 (which introduces annotated-assignments without values as types-only bindings) -- probably need to special case this particular situation of an annotation-only assignment of an imported name

@henzef
Copy link

henzef commented Mar 24, 2021

I think I have another example for this:

gvar: int

def set_var():
    global gvar
    gvar = 1

def print_var():
    print(gvar)

set_var()
print_var()

reports "F821 undefined name 'gvar'", which seems to be the same bug. Or should I open a separate issue?

@asottile
Copy link
Member

@henzef that's unrelated and covered in #621

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants