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

Unwanted newlines being added to output.

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

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

評価

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

調査の方向性

提供された Python 再現コードから始め、ネストされたテーブルが追加された後に tomlkit がどのようにテーブルをシリアライズするかを追跡します。round-trip 出力と変更後の出力を比較し、その後、改行の挙動を対象とするリグレッションテストを追加します。明示的に構築された構造に従ってテーブルの間隔が決まり、予期しない余分な改行が入らなければ完了です。

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

説明

I want to group my tables:

[first]
foo = 5
bar = 20
[first.a.b.c]
alice = 10
bob = 30

[second]       
foo = 3
bar = 21
[second.a.b.c]
alice = 15
bob = 3543

When I try to manually construct this, I instead get

[first]
foo = 5
bar = 20

[first.a.b.c]
alice = 10
bob = 30


[second]       
foo = 3
bar = 21

[second.a.b.c]
alice = 15
bob = 3543

I expected no newlines to be added for me and explicitly called out a newline between [first.a.b.c] table and [second]. Newlines being added surprised me and made made me wonder if tomlkit was properly preserving the lack of newlines but it seems to.

So I created the following test case to experiment with how newlines are dealt with

import tomlkit

t = tomlkit.loads("""[first]
foo = 5
bar = 20
[first.a.b.c]
alice = 10
bob = 30
[second]
foo = 3
bar = 21
[second.a.b.c]
alice = 15
bob = 3543""")

print("Round-trip")
print("```toml")
print(tomlkit.dumps(t))
print("```")
print()

t["second"].add("extra", tomlkit.table())
t["second"].add("extra1", tomlkit.table())
three = tomlkit.table()
three["foo"] = 2
three["bar"] = 1
child = tomlkit.table()
child["alice"] = 3
child["bob"] = 10
three["child"] = child
t["three"] = three


print("Changed")
print("```toml")
print(tomlkit.dumps(t))
print("```")
print()

The output is:
Round-trip

[first]
foo = 5
bar = 20
[first.a.b.c]
alice = 10
bob = 30
[second]
foo = 3
bar = 21
[second.a.b.c]
alice = 15
bob = 3543

Changed

[first]
foo = 5
bar = 20
[first.a.b.c]
alice = 10
bob = 30
[second]
foo = 3
bar = 21
[second.a.b.c]
alice = 15
bob = 3543
[second.extra]

[second.extra1]

[three]
foo = 2
bar = 1

[three.child]
alice = 3
bob = 10

I was surprised that second.extra didn't have a newline before it but second.extra1 did. I imagine this just shows how the newlines are being auto-added but it is still surprising.

主要言語
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 を短くまとめたダイジェスト。