Commit b47294e1 authored by Carlos Ramos Carreño's avatar Carlos Ramos Carreño

Execute `zip` eagerly.

The builtin `zip` in Python 3 returns an iterator, not a list.
Thus, one cannot directly use the `len` method on the object returned
by `zip`, or we will have errors like the following one:

```python
Traceback (most recent call last):
  File "/srv/slapgrid/slappart66/git/wendelin.core/wcfs/internal/xbtree/xbtreetest/treegen.py", line 617, in <module>
    main()
  File "/srv/slapgrid/slappart66/git/wendelin.core/wcfs/internal/xbtree/xbtreetest/treegen.py", line 613, in main
    cmd(argv)
  File "/srv/slapgrid/slappart66/venvs/wendelin.core/lib/python3.9/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "/srv/slapgrid/slappart66/git/pygolang/golang/__init__.py", line 125, in _
    return f(*argv, **kw)
  File "/srv/slapgrid/slappart66/git/wendelin.core/wcfs/internal/xbtree/xbtreetest/treegen.py", line 589, in cmd_trees
    TreesSrv(zstor, r)
  File "/srv/slapgrid/slappart66/venvs/wendelin.core/lib/python3.9/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "/srv/slapgrid/slappart66/git/pygolang/golang/__init__.py", line 125, in _
    return f(*argv, **kw)
  File "/srv/slapgrid/slappart66/git/wendelin.core/wcfs/internal/xbtree/xbtreetest/treegen.py", line 234, in TreesSrv
    treetxtPrev = zctx.ztreetxt(ztree)
  File "/srv/slapgrid/slappart66/venvs/wendelin.core/lib/python3.9/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "/srv/slapgrid/slappart66/git/pygolang/golang/__init__.py", line 125, in _
    return f(*argv, **kw)
  File "/srv/slapgrid/slappart66/git/wendelin.core/wcfs/internal/xbtree/xbtreetest/treegen.py", line 536, in ztreetxt
    return zctx.TopoEncode(xbtree.StructureOf(ztree))
  File "/srv/slapgrid/slappart66/venvs/wendelin.core/lib/python3.9/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "/srv/slapgrid/slappart66/git/pygolang/golang/__init__.py", line 125, in _
    return f(*argv, **kw)
  File "/srv/slapgrid/slappart66/git/wendelin.core/wcfs/internal/xbtree/xbtreetest/treegen.py", line 542, in TopoEncode
    return xbtree.TopoEncode(tree, zctx.vencode)
  File "/srv/slapgrid/slappart66/git/wendelin.core/wcfs/internal/xbtree.py", line 797, in TopoEncode
    for nodev in _walkBFS(tree):
  File "/srv/slapgrid/slappart66/git/wendelin.core/wcfs/internal/xbtree.py", line 701, in _walkBFS
    for level in __walkBFS(tree):
  File "/srv/slapgrid/slappart66/git/wendelin.core/wcfs/internal/xbtree.py", line 724, in __walkBFS
    assert len(rv) == len(rn.node.children)
TypeError: object of type 'zip' has no len()
```

Thus, we have to create a list from the result of `zip` before calling
`len` on it.
parent 3846997b
......@@ -720,7 +720,7 @@ def __walkBFS(tree): # i[] of [](of _NodeInRange on each level)
assert isinstance(rn.node, (Tree, Bucket))
if isinstance(rn.node, Tree):
v = (rn.range.klo,) + rn.node.keyv + (rn.range.khi,)
rv = zip(v[:-1], v[1:]) # (klo,k1), (k1,k2), ..., (kN,khi)
rv = list(zip(v[:-1], v[1:])) # (klo,k1), (k1,k2), ..., (kN,khi)
assert len(rv) == len(rn.node.children)
for i in range(len(rv)):
......@@ -771,7 +771,7 @@ def __zwalkBFS(ztree): # i[] of [](of _NodeInRange on each level)
panic("bad tree kind %r" % kind)
v = [rn.range.klo] + keyv + [rn.range.khi]
rv = zip(v[:-1], v[1:]) # (klo,k1), (k1,k2), ..., (kN,khi)
rv = list(zip(v[:-1], v[1:])) # (klo,k1), (k1,k2), ..., (kN,khi)
assert len(rv) == len(children)
for i in range(len(rv)):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment