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

Flake8 does not support typing.no_type_check #1113

Closed
asottile opened this issue Apr 3, 2021 · 7 comments
Closed

Flake8 does not support typing.no_type_check #1113

asottile opened this issue Apr 3, 2021 · 7 comments

Comments

@asottile
Copy link
Member

asottile commented Apr 3, 2021

In GitLab by @liiight on Nov 28, 2020, 08:40

I am not sure if this issue is even in the scope of what flake8 can or is supposed to do. I also looked for references to this prior to opening this issue. If this was previously discussed or is completely irrelevant, I apologize in advance.

Flake8 does not seem to take into consideration the typing.no_type_check decorator and throws F821 undefined name error,
Example (from Uplink's documentation, a great library with a custom use case for type annotation):

from uplink import Consumer, get, Path, Query
from typing import no_type_check


class GitHub(Consumer):
    """A Python Client for the GitHub API."""
    @no_type_check
    @get("users/{user}/repos")
    def get_repos(self, user: Path, sort_by: Query("sort")):
        """Get user's public repositories."""

Results of running flake8:

➜ flake8 flake8_poc.py
flake8_poc.py:9:52: F821 undefined name 'sort'

This raises no error when running using mypy for example.

Please describe how you installed Flake8

Via pip

Note: Some *nix distributions patch Flake8 arbitrarily to accommodate incompatible software versions. If you're on one of those distributions, your issue may be closed and you will be asked to open an issue with your distribution package maintainers instead.

Please provide the exact, unmodified output of flake8 --bug-report

{
  "dependencies": [],
  "platform": {
    "python_implementation": "CPython",
    "python_version": "3.6.12",
    "system": "Darwin"
  },
  "plugins": [
    {
      "is_local": false,
      "plugin": "mccabe",
      "version": "0.6.1"
    },
    {
      "is_local": false,
      "plugin": "pycodestyle",
      "version": "2.6.0"
    },
    {
      "is_local": false,
      "plugin": "pyflakes",
      "version": "2.2.0"
    }
  ],
  "version": "3.8.4"
}

Thank you in advance for your reply! Know that your efforts are highly appreciated.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @liiight on Nov 28, 2020, 08:41

changed the description

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @asottile on Nov 28, 2020, 09:15

please follow the issue template, notably:

<!--
*************************************************************************
NOTE: flake8 is a linting framework and does not implement any checks

if you are reporting a problem with a particular check, please track down
the plugin which implements that check.

some common ones:
- F###: https://github.com/pycqa/pyflakes
- E###, W###: https://github.com/pycqa/pycodestyle
*************************************************************************
-->

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @liiight on Nov 28, 2020, 10:11

Thanks, I apologize for opening this here

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @asottile on Nov 28, 2020, 10:15

an aside, I'd be very careful about using libraries which override type annotations to have custom behaviours -- they're all likely to break in python3.10 (or with from __future__ import annotations)

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @liiight on Nov 28, 2020, 10:18

hmm, good tip. I'll point the library author to it.
Thanks!

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @asottile on Nov 28, 2020, 10:20

you may also want to suggest PEP 593

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @liiight on Nov 28, 2020, 10:32

Thanks again.
I opened PyCQA/pyflakes#595, hopefully in the correct place this time.

I just want to point out that the wording the discenrs between flake8 and the checks that uses it could maybe be simplified or worded differently.
Something like:

NOTE: flake8 is a linting framework and does not implement any checks

Checks occur via plugins to the flake8 framework, and are not part of it's core.
If you are reporting a problem with a particular check, please track down
the plugin which implements that check. You can do that via its error code prefix letter.

Some common ones:
- F###: https://github.com/pycqa/pyflakes
- E###, W###: https://github.com/pycqa/pycodestyle

@asottile asottile closed this as completed Apr 3, 2021
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

No branches or pull requests

1 participant