Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

`Array.add_line()` doesn't serialize as documented (or expected) and can even produce syntactically invalid TOML

オープン
#580 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
python
領域
tooling

調査の方向性

Array.add_line から始め、as_string が1行の配列をどのようにシリアライズするかを追い、その後、コメントアウトされた例を再現して tomlkit.loads で出力を検証します。コメント付きの行を追加すると有効な TOML が生成され、結果の配列のシリアライズが一貫して複数行の動作を反映すれば完了です。直接シリアライズとドキュメントのシリアライズの両方について回帰テストを追加してください。

索引モデルが issue の本文から書いたものです。

説明

Update: This seems to be part of a larger problem; see my comment below for additional context.

If an Array isn't multiline, then calling its .add_line method doesn't add a trailing line separator. When the added line includes a comment, this causes .as_string and similar to produce invalid TOML:

>>> import tomlkit
>>> array = tomlkit.array()
>>> array.add_line("foo", comment="bar")
>>> print(array.as_string())
[
    "foo", # bar]
>>> doc = tomlkit.document()
>>> doc.add("array", array)
{'array': ['foo']}
>>> print(doc.as_string())
array = [
    "foo", # bar]

>>> tomlkit.loads(doc.as_string())
Traceback (most recent call last):
  File "<python-input-7>", line 1, in <module>
    tomlkit.loads(doc.as_string())
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/home/five35/.local/share/hatch/env/virtual/python-scripts/S8f9twao/python-scripts/lib/python3.14/site-packages/tomlkit/api.py", line 52, in loads
    return parse(string)
  File "/home/five35/.local/share/hatch/env/virtual/python-scripts/S8f9twao/python-scripts/lib/python3.14/site-packages/tomlkit/api.py", line 99, in parse
    return Parser(string).parse()
           ~~~~~~~~~~~~~~~~~~~~^^
  File "/home/five35/.local/share/hatch/env/virtual/python-scripts/S8f9twao/python-scripts/lib/python3.14/site-packages/tomlkit/parser.py", line 139, in parse
    item = self._parse_item()
  File "/home/five35/.local/share/hatch/env/virtual/python-scripts/S8f9twao/python-scripts/lib/python3.14/site-packages/tomlkit/parser.py", line 238, in _parse_item
    return self._parse_key_value(True)
           ~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/home/five35/.local/share/hatch/env/virtual/python-scripts/S8f9twao/python-scripts/lib/python3.14/site-packages/tomlkit/parser.py", line 331, in _parse_key_value
    val = self._parse_value()
  File "/home/five35/.local/share/hatch/env/virtual/python-scripts/S8f9twao/python-scripts/lib/python3.14/site-packages/tomlkit/parser.py", line 435, in _parse_value
    return self._parse_array()
           ~~~~~~~~~~~~~~~~~^^
  File "/home/five35/.local/share/hatch/env/virtual/python-scripts/S8f9twao/python-scripts/lib/python3.14/site-packages/tomlkit/parser.py", line 612, in _parse_array
    raise self.parse_error(UnexpectedCharError, self._current)
tomlkit.exceptions.UnexpectedCharError: Unexpected character: '\x00' at line 2 col 0

I think the simplest fix might be to make calling .add_line implicitly change single-line arrays to multiline. If nothing else, it doesn't make semantic sense to "add a line" to something which can't contain multiple lines, so hopefully that behavior wouldn't be surprising to anyone.

主要言語
Python
スター
850
フォーク
163
平均マージ
13分
マージ済み PR(30日)
2

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python-poetry/tomlkit のほかの issue

python-poetry/tomlkit の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。