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

TOML parse error: Invalid table header: Duplicate key #439

Closed
messense opened this issue Jan 15, 2023 · 2 comments · Fixed by #460
Closed

TOML parse error: Invalid table header: Duplicate key #439

messense opened this issue Jan 15, 2023 · 2 comments · Fixed by #460
Labels
A-parse Area: Parsing TOML C-bug Category: Things not working as expected

Comments

@messense
Copy link

messense commented Jan 15, 2023

# pyproject.toml

[tool.hatch]
version.source = "vcs"

[tool.hatch.version.raw-options]
local_scheme = "no-local-version"

Both toml and toml_edit fail to parse it:

// toml
Err(
    Error {
        inner: ErrorInner {
            kind: Custom,
            line: Some(
                5,
            ),
            col: 0,
            at: Some(
                55,
            ),
            message: "duplicate key: `version`",
            key: [
                "tool",
                "hatch",
            ],
        },
    },
)

// toml_edit
Err(
    TomlError {
        message: "TOML parse error at line 6, column 1\n  |\n6 | [tool.hatch.version.raw-options]\n  | ^\nInvalid table header\nDuplicate key `version`\n",
        line_col: Some(
            (
                5,
                0,
            ),
        ),
    },
)

while the Python tomllib has no issue with it

Python 3.11.0 (main, Oct 25 2022, 16:25:24) [Clang 14.0.0 (clang-1400.0.29.102)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tomllib as toml
>>> s = '''# pyproject.toml
...
... [tool.hatch]
... version.source = "vcs"
...
... [tool.hatch.version.raw-options]
... local_scheme = "no-local-version"'''
>>> toml.loads(s)
{'tool': {'hatch': {'version': {'source': 'vcs', 'raw-options': {'local_scheme': 'no-local-version'}}}}}

Rust Explorer Playground

See also astral-sh/ruff#1894

@epage
Copy link
Member

epage commented Jan 16, 2023

Your TOML sample looks similar to this section in the TOML spec

[fruit]
apple.color = "red"
apple.taste.sweet = true

# [fruit.apple]  # INVALID
# [fruit.apple.taste]  # INVALID

[fruit.apple.texture]  # you can add sub-tables
smooth = true

with the accompanying rule being

The [table] form can, however, be used to define sub-tables within tables defined via dotted keys.

@epage
Copy link
Member

epage commented Jan 16, 2023

Looking at getting this test case upstreamed into the compliance test suite: toml-lang/toml-test#129

@epage epage added C-bug Category: Things not working as expected A-parse Area: Parsing TOML labels Jan 16, 2023
epage added a commit to epage/toml_edit that referenced this issue Jan 18, 2023
epage added a commit to epage/toml_edit that referenced this issue Jan 18, 2023
epage added a commit to epage/toml_edit that referenced this issue Jan 18, 2023
epage added a commit to epage/toml_edit that referenced this issue Jan 18, 2023
epage added a commit to epage/toml_edit that referenced this issue Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parse Area: Parsing TOML C-bug Category: Things not working as expected
Projects
None yet
2 participants