An empty list or mapping is expanded as a defined value: `{x,v}` with `v=[]` gives `1,`, `{#v}` gives `#`, `{;v}` gives `;v=`
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Read uritemplate/variable.py, especially _string_expansion and _semi_path_expansion, and compare their handling of empty lists and mappings with _query_expansion and _label_path_expansion. Reproduce the reported cases with the Python command in the issue, then run the project and RFC uritemplate-test suites. Done when empty collections are treated as undefined in the affected expansions and the listed expected outputs pass.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Python
- Stars
- 246
- Forks
- 41
- Avg merge
- 8h 20m
- Merged PRs (30d)
- 3
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
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-hyper/uritemplate
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
python-hyper/uritemplate#163 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
python-hyper/uritemplate#51 ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
python-hyper/uritemplate#34 · 4 comments ·
-
Provide an API for validating URI TemplatesPossibly taken @sigmavirus24 claimed this 3380 days ago. Open
Difficulty 5/5 Over a week Newbie friendliness 35/100
python-hyper/uritemplate#33 · 9 comments ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
python-hyper/uritemplate#15 ·
All issues in python-hyper/uritemplate
Similar issues
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
fossasia/visdom-dev#69 ·
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
BUG: PROD: v1.3.0-beta Onboarding Profile Picture Misaligns When Name Validation Error AppearsPossibly taken @RitikaSen27 claimed this today. Openbug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
AOSSIE-Org/PictoPy#1647 · 2 comments ·
Maintainers usually reply within 2 days
-
[oblt-aw][autodoc] Update workflow docs for gh-aw v0.92.5 and detector permission scopePossibly taken @github-actions claimed this today. Open
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day