https://pantsbuild.org/ logo
h

hundreds-breakfast-49010

12/19/2019, 11:16 PM
do we have any good way to push a dict or dict-like object across the FFI boundary, other than encoding it as a tuple of pairs?
a

aloof-angle-91616

12/19/2019, 11:21 PM
what else do you have in mind?
h

hundreds-breakfast-49010

12/19/2019, 11:23 PM
I'd like to be able to have a python object returned from the engine just include a dictionary, but I don't think this is safe because dictionaries aren't hashable
and there's no dictionary equivalent of a frozenset
a

aloof-angle-91616

12/19/2019, 11:42 PM
we can do what twitter.common.collections does with OrderedSet and just have a frozenset of keys and a dict
but it’s not hard to add a dict to an object returned by the engine just with what we have now
converting to a vector of tuples as we already do is probably hashable
h

hundreds-breakfast-49010

12/19/2019, 11:55 PM
hm, I thought that a type we returned from an engine intrinsic had to be marked
@dataclass(frozen=True)
(or otherwise hashable), and that this precluded using a
Dict
as one of the fields, but apparently this works fine?
a

aloof-angle-91616

12/19/2019, 11:55 PM
oh, hm
(1) we can override the hash method (I LITERALLY HATE SLACK’S WYSIWYG EDITOR!!!)
(2) we can make the dataclass object actually contain a tuple of tuples, and then convert it into a dict with an @memoized_property
h

hundreds-breakfast-49010

12/19/2019, 11:59 PM
so is it actually incorrect for a type returned from an engine intrinsic to have a
Dict
field? I thought that either typechecking or some runtime check would catch this if it wasn't okay, but it seems to work fine
a

aloof-angle-91616

12/20/2019, 12:00 AM
can you call hash() on it?
h

hundreds-breakfast-49010

12/20/2019, 12:01 AM
nope, dict is unhashable
a

aloof-angle-91616

12/20/2019, 12:02 AM
that will lead to an error when externs::identify is called on the object