Skip to content
This repository was archived by the owner on Jun 3, 2023. It is now read-only.
This repository was archived by the owner on Jun 3, 2023. It is now read-only.

Can't create maps that use a list as key #35

@souenzzo

Description

@souenzzo

Hello

I'm trying to use EQL from Python

It's a query language, similar to datomic "selector/pull-pattern"

The quey that I need to run is something like [{(:a {:b 42}) [:c]}]

But when I try, i get errors like

Traceback (most recent call last):
  File "...", line 243, in <module>
    cmap_issue()
  File "....", line 226, in cmap_issue
    t.frozendict([[in_key, in_value]]),  ## This will throw because in_key isn't hashable
  File ".../site-packages/transit/transit_types.py", line 167, in __init__
    self._dict = dict(*args, **kwargs)
  File ".../site-packages/transit/transit_types.py", line 124, in __hash__
    return reduce(lambda a, b: hash(a) ^ hash(b), self.rep, 0)
NameError: name 'reduce' is not defined

Here the code that I use

from pprint import pprint
import io
from transit.writer import Writer
from transit.reader import Reader
import transit.transit_types as t


def cmap_issue():
    ## value: [{(:a {:b 42}) [:c]}]
    in_key = t.List([t.Keyword("a"), t.frozendict({t.Keyword("b"): 42})])
    ## in_key = t.Keyword("a") ## << this one works!
    in_value = t.Vector([t.Keyword("c")])
    input = t.Vector([
        t.frozendict([[in_key, in_value]]),  ## This will throw because in_input isn't hashable
        t.TaggedValue("cmap", [in_key, in_value])  ## This way works with both inputs, but uses internal "cmap" concept
    ])
    baos = io.StringIO()
    writer = Writer(baos, "json")
    writer.write(input)
    transit = baos.getvalue()
    bais = io.StringIO(transit)
    reader = Reader("json")
    output = reader.read(bais)
    pprint([
        "input", input,
        "transit", transit.encode("ascii"),
        "output", output,
    ])

You can remove the second in_key comment to make the code work

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions