Comment not parsed when value is boolean
还没有人认领这个 Issue。
评估
调研方向
从 tomlkit.loads 的复现开始,跟踪 d["foo"] 下的值是如何创建的,并将 boolean 路径与 integer 和 string 路径进行比较。当 boolean 值通过 trivia.comment 暴露其尾随注释,并与现有行为及提供的复现一致时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- Python
- 星标
- 850
- 派生
- 163
- 平均合并
- 13 分钟
- 30 天内合并 PR
- 2
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python-poetry/tomlkit 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
python-poetry/tomlkit#546 · 2 条评论 ·
-
难度 3/5 1-2 天 新手友好度 68/100
python-poetry/tomlkit#603 ·
-
难度 3/5 1-2 天 新手友好度 52/100
python-poetry/tomlkit#580 · 1 条评论 ·
-
难度 3/5 1-2 天 新手友好度 72/100
python-poetry/tomlkit#577 ·
-
难度 5/5 一周以上 新手友好度 20/100
python-poetry/tomlkit#574 · 5 条评论 ·
查看 python-poetry/tomlkit 的全部 Issue
相似的 Issue
-
agent-ready documentation needs-triage
难度 1/5 1-3 小时 新手友好度 88/100
-
documentation
难度 1/5 1 小时以内 新手友好度 91/100
-
workflow-status page template still says reusable workflows are "triggered only by workflow_call:" 未关闭
难度 1/5 1 小时以内 新手友好度 92/100
-
instance instance add
难度 1/5 1 小时以内 新手友好度 72/100
searxng/searx-instances#939 · 1 条评论 ·
-
area-deployment area-integrations triage:bot-seen
难度 2/5 半天 新手友好度 86/100