运行 黑色导致错误 "This float doesn't have a leading digit"

Running black causes error "This float doesn't have a leading digit"

当我尝试使用 black a_file.py 在我的 python 项目的特定文件上 运行 black 时,出现以下错误:

 Error reading configuration file: This float doesn't have a leading digit (line 19 column 1 char 205)

下面是我的 pyproject.toml 文件:

[tool.black]
line-length = 88
include = '\.pyi?$'
exclude = '''
/(
    \.git
  | \.hg
  | \.mypy_cache
  | \.tox
  | \.venv
  | buck-out
  | build
)/
'''

[flake8]
max-line-length = 88
max-complexity = 18
select = B, C, E, F, W, T4, B9
ignore = E203, E266, E501, W503, F403, F401

我该如何解决这个问题?

这是您的 pyproject.toml 文件使用不正确语法的问题。例如,select = B, C, E, F, W, T4, B9 这样的行是 INI-syntax – 在 TOML 中,等价的是 select = "B, C, E, F, W, T4, B9"select = ["B", "C", "E", "F", "W", "T4", "B9"].

但是,flake8 does not yet support pyproject.toml 首先。只需从文件中删除其配置。

Configuration Locations

Flake8 supports storing its configuration in your project in one of setup.cfg, tox.ini, or .flake8.