Skip to content

Valid toml syntax causes black to crash #2280

@nat-n

Description

@nat-n

Describe the bug

I have a pyproject.toml for configuring various other tools (not black), which includes a list with mixed type contents, as explicitly support by the v1.0.0 of the toml spec.

When I run black it crashes with a cryptic traceback from inside the toml library.

To Reproduce

mkdir new_project
cat <<EOT > ./new_project/pyproject.toml
# this example is from the toml spec
contributors = [
  "Foo Bar <foo@example.com>",
  { name = "Baz Qux", email = "bazqux@example.com", url = "https://example.com/bazqux" }
]
EOT
cd new_project
black .

Expected behavior

It shouldn't crash.

Environment (please complete the following information):

  • Version: black, version 21.5b1
  • OS and Python version: MacOs Python 3.8.8

Since the presently used "toml" library explicitly only supports up to version 0.5.0 of the spec (from about two years ago), I'd suggest switching to tomlkit, which supports the current toml spec (officially up to 1.0.0rc1 but nothing has materially changed since then).

I'd be happy to put together a PR if this approach is deemed acceptable in principle.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions