`Array.add_line()` doesn't serialize as documented (or expected) and can even produce syntactically invalid TOML
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 52/100
Direzione di ricerca
Inizia da Array.add_line e segui il modo in cui as_string serializza gli array su una singola riga, quindi riproduci l’esempio commentato e verifica l’output tramite tomlkit.loads. Il lavoro è completato quando l’aggiunta di una riga con un commento produce TOML valido e la serializzazione risultante dell’array riflette coerentemente il comportamento multilinea; aggiungi una copertura di regressione per la serializzazione diretta e quella del documento.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 850
- Fork
- 163
- Merge medio
- 13m
- PR unite (30g)
- 2
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di python-poetry/tomlkit
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
python-poetry/tomlkit#546 · 2 commenti ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
python-poetry/tomlkit#603 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
python-poetry/tomlkit#577 ·
-
Looking for a co-maintainer Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
python-poetry/tomlkit#574 · 5 commenti ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
python-poetry/tomlkit#571 ·
Tutte le issue di python-poetry/tomlkit
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
anthropics/skills#1811 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
speaches-ai/speaches#678 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
datalayer/mcp-compose#42 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
conda-forge/spacy-feedstock#177 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
UKGovernmentBEIS/inspect_evals#2523 ·