Comment not parsed when value is boolean
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start with the tomlkit.loads reproduction and trace how values under d["foo"] are created, comparing the boolean path with the integer and string paths. Done means a boolean value exposes its trailing comment through trivia.comment, matching the existing behavior and the supplied reproduction.
Written by the indexing model from the issue text.
Description
I've just tried to set up comment parsing in a TOML config file to see if I could use it for documentation, and it seems like it'll work except for when the configured value is a boolean.
When I drop into a debugger and look at the attributes of the parsed value:
(Pdb) p default_toml[section]
{'CONVERT_TO_PDF': False}
(Pdb) x = default_toml[section]
(Pdb) y = x["CONVERT_TO_PDF"]
and then tab complete to show the attributes, the dict x has a trivia attribute but the value y does not:
(Pdb) p y.
y.__abs__ y.__floor__ y.__invert__ y.__radd__ y.__rpow__ y.__trunc__
y.__add__ y.__floordiv__ y.__le__ y.__rand__ y.__rrshift__ y.__xor__
y.__and__ y.__format__ y.__lshift__ y.__rdivmod__ y.__rshift__ y.as_integer_ratio
y.__bool__ y.__ge__ y.__lt__ y.__reduce__ y.__rsub__ y.bit_length
y.__ceil__ y.__getattribute__ y.__mod__ y.__reduce_ex__ y.__rtruediv__ y.conjugate
y.__class__ y.__getnewargs__ y.__mul__ y.__repr__ y.__rxor__ y.denominator
y.__delattr__ y.__gt__ y.__ne__ y.__rfloordiv__ y.__setattr__ y.from_bytes
y.__dir__ y.__hash__ y.__neg__ y.__rlshift__ y.__sizeof__ y.imag
y.__divmod__ y.__index__ y.__new__ y.__rmod__ y.__str__ y.numerator
y.__doc__ y.__init__ y.__or__ y.__rmul__ y.__sub__ y.real
y.__eq__ y.__init_subclass__ y.__pos__ y.__ror__ y.__subclasshook__ y.to_bytes
y.__float__ y.__int__ y.__pow__ y.__round__ y.__truediv__
- I checked in
x.trivia.commentbut there's nothing there - For other types of value (integer, float and string) comments are expected to be in the
trivia.commentattribute
Is this a bug, or should I be looking for the comment in another place?
To minimally reproduce:
import tomlkit
d = tomlkit.loads("""
[foo]
bar = 1 # hello
baz = false # goodbye
""")
v1 = d["foo"]["bar"]
v2 = d["foo"]["baz"]
print(hasattr(v1, "trivia"))
print(getattr(v1.trivia, "comment"))
print(hasattr(v2, "trivia"))
⇣
True
# hello
False
- Dominant language
- Python
- Stars
- 850
- Forks
- 163
- Avg merge
- 13m
- Merged PRs (30d)
- 2
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python-poetry/tomlkit
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
python-poetry/tomlkit#546 · 2 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
python-poetry/tomlkit#603 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
python-poetry/tomlkit#580 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
python-poetry/tomlkit#577 ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
python-poetry/tomlkit#574 · 5 comments ·
All issues in python-poetry/tomlkit
Similar issues
-
area: harness bug status: needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Human-Agent-Society/reef#625 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 1/5 Under an hour Newbie friendliness 80/100
learningequality/kolibri#15351 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Name consistency Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
eellak/triplestore#65 · 1 comment ·