Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

An empty list or mapping is expanded as a defined value: `{x,v}` with `v=[]` gives `1,`, `{#v}` gives `#`, `{;v}` gives `;v=`

未關閉 適合新手
#164 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
78/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
backend

研究方向

閱讀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 checked against an independent implementation (uri-template 1.3.0 on PyPI): it gives '1' and '' for the first two cases, and ';v' for {;v} with {}, which is not the RFC's empty string either, so the RFC text alone decides that row.

主要語言
Python
星號
246
分支
41
平均合併
8 小時 20 分鐘
30 天內合併 PR
3

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

python-hyper/uritemplate 的其他 Issue

查看 python-hyper/uritemplate 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。