An empty list or mapping is expanded as a defined value: `{x,v}` with `v=[]` gives `1,`, `{#v}` gives `#`, `{;v}` gives `;v=`
还没有人认领这个 Issue。
评估
调研方向
阅读uritemplate/variable.py,重点查看_string_expansion和_semi_path_expansion,并将它们对空列表和映射的处理方式与_query_expansion和_label_path_expansion进行比较。使用 issue 中的 Python 命令重现报告的案例,然后运行项目和 RFC uritemplate-test测试套件。受影响的扩展将空集合视为未定义,并且列出的预期输出均通过后,即算完成。
由索引模型根据 Issue 内容生成。
描述
Versions tested: uritemplate 4.2.0 from PyPI (the newest release on 2026-10-23) and the main branch at
8e46228e5a1ad3f688b21c6b3917d15dd0f7c581 (its head on 2026-10-23); CPython 3.10 and 3.11 on Linux.
Reproduce (one command):
python3 -c 'from uritemplate import expand; print(repr(expand("{x,v}", {"x": "1", "v": []})))'
An empty list is an ordinary value for a variable that has none to give, and RFC 6570 covers it.
Expected: '1'. RFC 6570 section 2.3: "A variable defined as a list value is considered undefined if the list contains zero members. A
variable defined as an associative array of (name, value) pairs is considered undefined if the array contains zero members or if all member
names in the array are associated with undefined values." Section 3.2.1: "A variable that is undefined (Section 2.3) has no value and is ignored by the expansion process. If all of the
variables in an expression are undefined, then the expression's expansion is the empty string." The algorithm in Appendix A says the same:
"If the varname is unknown or corresponds to a variable with an undefined value (Section 2.3), then skip to the next varspec". The separator
is appended only between defined variables.
Observed (the same on 4.2.0 and on main):
'1,'
More cases, all with x="1" (tool output / what the RFC text gives):
| template | v | observed | expected |
|---|---|---|---|
{+x,v} |
[] |
1, |
1 |
{#x,v} |
[] |
#1, |
#1 |
{#v} |
[] or {} |
# |
(empty) |
{;x,v} |
[] |
;x=1;v= |
;x=1 |
{;v} |
{} |
;v= |
(empty) |
{;v*} |
{} |
; |
(empty) |
Controls, correct today: {/x,v} -> /1, {.x,v} -> .1, {?x,v} -> ?x=1, {&x,v} -> &x=1, and {x,w} with w not given -> 1.
Where
In uritemplate/variable.py (same on main and in 4.2.0), _query_expansion returns None for an empty list or mapping (if not value: return None, in both the list and the mapping branch) and _label_path_expansion does the same (len(value) == 0), which is why /, ., ? and & are correct. _string_expansion (used by the simple, + and # operators) has no such check, and _semi_path_expansion has it only in its list-explode branch ({;v*} with [] correctly gives ''), so in the other cases the empty collection is expanded as a defined, empty value. Adding the same early return to those two functions made every case above agree with the RFC text and left the project's own test suite and the RFC's uritemplate-test suite green on this machine; that is only a local check, not a proposed patch.
Found by comparing the library with a small model of the RFC's expansion algorithm on generated templates and values, then confirmed against an independent implementation (uri-template 1.3.0 on PyPI), which gives '1', '' and ';v' for the three cases.
- 主要语言
- Python
- 星标
- 246
- 派生
- 41
- 平均合并
- 8 小时 20 分钟
- 30 天内合并 PR
- 3
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python-hyper/uritemplate 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 85/100
python-hyper/uritemplate#163 ·
-
难度 3/5 1-2 天 新手友好度 35/100
python-hyper/uritemplate#51 ·
-
难度 5/5 一周以上 新手友好度 25/100
python-hyper/uritemplate#34 · 4 条评论 ·
-
Provide an API for validating URI Templates可能已有人在做 @sigmavirus24 于 3380 天前认领。 未关闭
难度 5/5 一周以上 新手友好度 35/100
python-hyper/uritemplate#33 · 9 条评论 ·
-
enhancement
难度 2/5 1-3 小时 新手友好度 45/100
python-hyper/uritemplate#15 ·
查看 python-hyper/uritemplate 的全部 Issue
相似的 Issue
-
[oblt-aw][autodoc] Update workflow docs for gh-aw v0.92.5 and detector permission scope可能已有人在做 @github-actions 今天认领。 未关闭
难度 1/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
roadmap-100
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
comp/tools P2 tool/browser tool/file type/bug
难度 2/5 1-3 小时 新手友好度 75/100
NousResearch/hermes-agent#143418 · 1 条评论 ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 74/100
prestonbrown/helixscreen#1867 ·
维护者通常 2 天内回复