Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
dict() from a sequence: use the iteration protocol on the pairs
init_from_list read item.length and item[0]/item[1] as raw JS properties,
so dict() over a sequence of Python sequence objects (e.g. instances with
__len__/__getitem__) failed with 'has length undefined; 2 is required'.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
  • Loading branch information
zalo and claude committed Aug 13, 2026
commit 445334a5ad33df16aadeac48fcd3c9219e64bf0e
10 changes: 7 additions & 3 deletions www/src/py_dict.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,11 +712,15 @@ dict.tp_hash = _b_.None
function init_from_list(self, args) {
var i = 0
for (var item of args) {
if (item.length != 2) {
// item may be any Python sequence (eg an instance of a class with
// __iter__), not only a JS array: use the iteration protocol
var pair = Array.isArray(item) ? item :
Array.from($B.make_js_iterator_no_trace(item))
if (pair.length != 2) {
$B.RAISE(_b_.ValueError, "dictionary " +
`update sequence element #${i} has length ${item.length}; 2 is required`)
`update sequence element #${i} has length ${pair.length}; 2 is required`)
}
dict.$setitem(self, item[0], item[1])
dict.$setitem(self, pair[0], pair[1])
i++
}
}
Expand Down