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

Spurious F821 error emitted by pyflakes due to forward references #278

Closed
nipunn1313 opened this issue Aug 26, 2022 · 1 comment · Fixed by #364
Closed

Spurious F821 error emitted by pyflakes due to forward references #278

nipunn1313 opened this issue Aug 26, 2022 · 1 comment · Fixed by #364

Comments

@nipunn1313
Copy link

Repro:

from typing import List
class Outer:
    class Inner1: ...
    class Inner2(List[Outer.Inner1]): ...

Both mypy and pyright are happy with this
flake8 complains that it can't identify the name Outer

Within a .py file, this construct would not be ok, but it appears to be ok within a .pyi file.

This may be because mypy/pyright do a 2-pass check. I am not sure how flake8/flake8-pyi works here.

@AlexWaygood
Copy link
Collaborator

AlexWaygood commented Aug 26, 2022

So, the issue here is that F821 isn't anything to do with flake8-pyi per se — it's triggered by pyflakes, one of the builtin flake8 plugins. Unfortunately, neither pyflakes nor flake8 have ever claimed to support stub files, and pyflakes doesn't really understand some of the important semantic differences between.py files and .pyi files, including the fact that forward references are natively supported in stubs.

Ideally we'd submit patches upstream to make pyflakes .pyi-compatible (#183), but:

  1. I'm not sure if upstream would be receptive
  2. It might be a fair bit of work (I don't know!)
  3. Nobody's got round to it yet/there's always been lower-hanging fruit to work on :)

@AlexWaygood AlexWaygood changed the title FDecl class resolution Spurious F821 error emitted by pyflakes due to forward references Aug 26, 2022
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.

2 participants