OILS / builtin / method_dict.py View on Github | oilshell.org

45 lines, 23 significant
1"""Methods on YSH Dict"""
2
3from __future__ import print_function
4
5from _devbuild.gen.value_asdl import (value, value_t)
6
7from core import vm
8from frontend import typed_args
9from mycpp.mylib import log
10
11from typing import List
12
13_ = log
14
15
16class Keys(vm._Callable):
17
18 def __init__(self):
19 # type: () -> None
20 pass
21
22 def Call(self, rd):
23 # type: (typed_args.Reader) -> value_t
24
25 dictionary = rd.PosDict()
26 rd.Done()
27
28 keys = [value.Str(k) for k in dictionary.keys()] # type: List[value_t]
29 return value.List(keys)
30
31
32class Values(vm._Callable):
33
34 def __init__(self):
35 # type: () -> None
36 pass
37
38 def Call(self, rd):
39 # type: (typed_args.Reader) -> value_t
40
41 dictionary = rd.PosDict()
42 rd.Done()
43
44 values = dictionary.values() # type: List[value_t]
45 return value.List(values)