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

Mixed type arrays in pyproject.toml lead to error #47

Open
apirogov opened this issue May 11, 2023 · 3 comments
Open

Mixed type arrays in pyproject.toml lead to error #47

apirogov opened this issue May 11, 2023 · 3 comments
Assignees
Labels
bug Something isn't working stale

Comments

@apirogov
Copy link

apirogov commented May 11, 2023

Description

TOML 1.0.0 supports mixed type arrays, but the toml library does not, leading to parsing errors.

Steps to Reproduce

This is a valid poetry pyproject.toml working without issues:

[tool.poetry]
name = "dummy-project"
version = "0.1.0"
description = ""
authors = ["John Doe <[email protected]>"]
readme = "README.md"
packages = [{include = "dummy_project"}]

include = [
  # having both a string and an object here seems to trigger the problem:
  "CHANGELOG.md",
  { path = "tests", format = "sdist" },
  # ----
]

[tool.poetry.dependencies]
python = "^3.8"
pyproject-parser = "^0.8.0"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

Now let's parse it:

import pyproject_parser
pyproject_parser.PyProject.load("pyproject.toml")

Actual result:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/local/home/a.pirogov/.cache/pypoetry/virtualenvs/dummy-project-oiKNdZ99-py3.8/lib/python3.8/site-packages/pyproject_parser/__init__.py", line 176, in load
    config = dom_toml.load(filename)
  File "/local/home/a.pirogov/.cache/pypoetry/virtualenvs/dummy-project-oiKNdZ99-py3.8/lib/python3.8/site-packages/dom_toml/__init__.py", line 217, in load
    return loads(
  File "/local/home/a.pirogov/.cache/pypoetry/virtualenvs/dummy-project-oiKNdZ99-py3.8/lib/python3.8/site-packages/dom_toml/__init__.py", line 171, in loads
    return toml.loads(  # type: ignore[return-value]
  File "/local/home/a.pirogov/.cache/pypoetry/virtualenvs/dummy-project-oiKNdZ99-py3.8/lib/python3.8/site-packages/toml/decoder.py", line 511, in loads
    ret = decoder.load_line(line, currentlevel, multikey,
  File "/local/home/a.pirogov/.cache/pypoetry/virtualenvs/dummy-project-oiKNdZ99-py3.8/lib/python3.8/site-packages/toml/decoder.py", line 778, in load_line
    value, vtype = self.load_value(pair[1], strictly_valid)
  File "/local/home/a.pirogov/.cache/pypoetry/virtualenvs/dummy-project-oiKNdZ99-py3.8/lib/python3.8/site-packages/toml/decoder.py", line 880, in load_value
    return (self.load_array(v), "array")
  File "/local/home/a.pirogov/.cache/pypoetry/virtualenvs/dummy-project-oiKNdZ99-py3.8/lib/python3.8/site-packages/toml/decoder.py", line 1002, in load_array
    a[b] = a[b] + ',' + a[b + 1]
IndexError: list index out of range

Expected result:

No exception.

Reproduces how often:

Always

Version

  • Python: 3.8
  • pyproject-parser: 0.8

Installation source

PyPI

Other Additional Information:

I think the simplest fix would be to switch from the toml to the tomli library, which parses the file just fine.

@domdfcoding
Copy link
Member

Can you try with version 0.9.0b2? That version replaces the old toml library with tomli/tomllib so should support TOML 1.0.0

@apirogov
Copy link
Author

With 0.9.0b2 it loads just fine! :) Then I hope 0.9 is fully released soon!

@domdfcoding
Copy link
Member

@apirogov I've released 0.9.0

@stale stale bot added the stale label Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale
Projects
None yet
Development

No branches or pull requests

2 participants