1

I installed Pyton 3.6.8 on my system.

python3 --version   //-> Python 3.6.8
python3.6 --version //-> Python 3.6.8

My pre-commit-config.yaml is:

repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
-   repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
hooks:
- id: flake8
  language_version: python3.6

I installed the pre-commit hook for my project. Every time when I want to commit some changes to git, the pre-commit is running with the flake8 error:

TYP005 NamedTuple does not support defaults in 3.6.0

This is true for Python 3.6.0, because this feature is introduced and allowed with Python 3.6.1+. https://docs.python.org/3.6/library/typing.html#typing.NamedTuple

How can I configure flake8 to run with Python 3.6.8?

EDIT When I run flake8 file.rb, I don`t get the error message TYP005.

python3 -m pip install flake
flake --version //-> 3.7.9 (the same version as in the pre-commit script file)
anthony sottile
  • 61,815
  • 15
  • 148
  • 207
user5580578
  • 1,134
  • 1
  • 12
  • 28
  • `language_version: python3.6.8`? Or is that an executable? I assume you're using https://pre-commit.com. Do you have any other flake8 config? What happens if you run it other than by pre-commit? – jonrsharpe Mar 13 '20 at 07:40
  • Yes I use pre-commit.com. If I use python3.6.8 I still get the same error. I`ve no further flake8 config files. – user5580578 Mar 13 '20 at 07:59
  • What if you run flake8 directly? Maybe you *should* have other config. – jonrsharpe Mar 13 '20 at 07:59
  • when I run flake8 file.rb I do not get this error message. Installed by; python3 -m pip install flake8. Furthermore flake8 --version is also 3.7.9 – user5580578 Mar 13 '20 at 08:02
  • Please [edit] this information into the question. – jonrsharpe Mar 13 '20 at 08:03

1 Answers1

4

disclaimer: I'm the author of two of the tools in question (pre-commit, flake8-typing-imports) and the maintainer of the other (flake8)


the TYP005 code comes from flake8-typing-imports

there are two options for indicating your minimum supported version to flake8-typing-imports, the first is a command line argument / flake8 setting:

--min-python-version 3.6.1

or in your flake8 configuration

[flake8]
min_python_version = 3.6.1

if you're distributing a library, you can indicate the minimum supported version using the python_requires metadata -- this is specified in setup.cfg

[options]
python_requires >= 3.6.1

an aside, I believe there's some information missing from your question, without additional_dependencies in your pre-commit configuration, flake8 will be installed in isolation and won't have access to plugins such as flake8-typing-imports -- my guess is you've actually got a configuration similar to:


-   repo: https://gitlab.com/pycqa/flake8
    rev: 3.7.9
    hooks:
    -   id: flake8
        additional_dependencies: [flake8-typing-imports==1.9.0]

when speaking of command line arguments above, you could specify them as args here (though I personally prefer the configuration file approaches)

    -   id: flake8
        args: [--min-python-version, '3.6.1']
        additional_dependencies: [flake8-typing-imports==1.9.0]
anthony sottile
  • 61,815
  • 15
  • 148
  • 207