omlish 0.0.0.dev119__py3-none-any.whl → 0.0.0.dev120__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
omlish/__about__.py CHANGED
@@ -1,5 +1,5 @@
1
- __version__ = '0.0.0.dev119'
2
- __revision__ = 'abf03cc06fe1610ddf750a1392aa9c9de00acfd3'
1
+ __version__ = '0.0.0.dev120'
2
+ __revision__ = 'aada6beb1d685cb095429e9c588d266b8a83aa23'
3
3
 
4
4
 
5
5
  #
@@ -1,6 +1,10 @@
1
1
  """
2
2
  TODO:
3
- - @omlish-lite
3
+ - @omlish-lite ?
4
+ - 'recipes'
5
+ - abstract runtime
6
+ - https://github.com/wrmsr/omnibus/blob/c2ff67b6c5c80aa03fe27a9b6f36212f3212c7ca/omnibus/jmespath/eval.py#L64
7
+ - pytest-ify
4
8
 
5
9
  Applied:
6
10
  https://github.com/jmespath-community/python-jmespath/compare/bbe7300c60056f52413603cf3e2bcd0b6afeda3d...aef45e9d665de662eee31b06aeb8261e2bc8b90a
@@ -20,9 +20,15 @@ class LeafNode(Node, lang.Abstract):
20
20
  return []
21
21
 
22
22
 
23
+ UnaryArithmeticOperator: ta.TypeAlias = ta.Literal[
24
+ 'plus',
25
+ 'minus',
26
+ ]
27
+
28
+
23
29
  @dc.dataclass(frozen=True)
24
30
  class ArithmeticUnary(Node, lang.Final):
25
- operator: str
31
+ operator: UnaryArithmeticOperator
26
32
  expression: Node
27
33
 
28
34
  @property
@@ -30,9 +36,19 @@ class ArithmeticUnary(Node, lang.Final):
30
36
  return [self.expression]
31
37
 
32
38
 
39
+ ArithmeticOperator: ta.TypeAlias = ta.Literal[
40
+ 'div',
41
+ 'divide',
42
+ 'minus',
43
+ 'modulo',
44
+ 'multiply',
45
+ 'plus',
46
+ ]
47
+
48
+
33
49
  @dc.dataclass(frozen=True)
34
50
  class Arithmetic(Node, lang.Final):
35
- operator: str
51
+ operator: ArithmeticOperator
36
52
  left: Node
37
53
  right: Node
38
54
 
@@ -51,9 +67,19 @@ class Assign(Node, lang.Final):
51
67
  return [self.expr]
52
68
 
53
69
 
70
+ ComparatorName: ta.TypeAlias = ta.Literal[
71
+ 'eq',
72
+ 'ne',
73
+ 'lt',
74
+ 'gt',
75
+ 'lte',
76
+ 'gte',
77
+ ]
78
+
79
+
54
80
  @dc.dataclass(frozen=True)
55
81
  class Comparator(Node, lang.Final):
56
- name: str
82
+ name: ComparatorName
57
83
  first: Node
58
84
  second: Node
59
85
 
@@ -638,6 +638,14 @@ class ObjectFunctions(FunctionsClass):
638
638
  def _func_values(self, arg):
639
639
  return list(arg.values())
640
640
 
641
+ @signature({'types': ['expref']}, {'types': ['object']})
642
+ def _func_filter_keys(self, expref, arg):
643
+ return {k: v for k, v in arg.items() if expref.visit(expref.expression, k)}
644
+
645
+ @signature({'types': ['expref']}, {'types': ['object']})
646
+ def _func_filter_values(self, expref, arg):
647
+ return {k: v for k, v in arg.items() if expref.visit(expref.expression, v)}
648
+
641
649
 
642
650
  class KeyedFunctions(FunctionsClass):
643
651
  def _create_key_func(self, expref, allowed_types, function_name):
@@ -27,9 +27,11 @@ import typing as ta
27
27
  from ... import check
28
28
  from .ast import AndExpression
29
29
  from .ast import Arithmetic
30
+ from .ast import ArithmeticOperator
30
31
  from .ast import ArithmeticUnary
31
32
  from .ast import Assign
32
33
  from .ast import Comparator
34
+ from .ast import ComparatorName
33
35
  from .ast import CurrentNode
34
36
  from .ast import Expref
35
37
  from .ast import Field
@@ -52,6 +54,7 @@ from .ast import Projection
52
54
  from .ast import RootNode
53
55
  from .ast import Slice
54
56
  from .ast import Subexpression
57
+ from .ast import UnaryArithmeticOperator
55
58
  from .ast import ValueProjection
56
59
  from .ast import VariableRef
57
60
  from .exceptions import IncompleteExpressionError
@@ -491,15 +494,15 @@ class Parser:
491
494
 
492
495
  def _parse_comparator(self, left: Node, comparator: str) -> Node:
493
496
  right = self._expression(self.BINDING_POWER[comparator])
494
- return Comparator(comparator, left, right)
497
+ return Comparator(ta.cast(ComparatorName, comparator), left, right)
495
498
 
496
499
  def _parse_arithmetic_unary(self, token: Token) -> Node:
497
500
  expression = self._expression(self.BINDING_POWER[token['type']])
498
- return ArithmeticUnary(token['type'], expression)
501
+ return ArithmeticUnary(ta.cast(UnaryArithmeticOperator, token['type']), expression)
499
502
 
500
503
  def _parse_arithmetic(self, left: Node, operator: str) -> Node:
501
504
  right = self._expression(self.BINDING_POWER[operator])
502
- return Arithmetic(operator, left, right)
505
+ return Arithmetic(ta.cast(ArithmeticOperator, operator), left, right)
503
506
 
504
507
  def _parse_multi_select_list(self) -> Node:
505
508
  expressions: list[Node] = []
@@ -6,9 +6,11 @@ from ... import check
6
6
  from ... import lang
7
7
  from .ast import AndExpression
8
8
  from .ast import Arithmetic
9
+ from .ast import ArithmeticOperator
9
10
  from .ast import ArithmeticUnary
10
11
  from .ast import Assign
11
12
  from .ast import Comparator
13
+ from .ast import ComparatorName
12
14
  from .ast import CurrentNode
13
15
  from .ast import Expref
14
16
  from .ast import Field
@@ -31,6 +33,7 @@ from .ast import Projection
31
33
  from .ast import RootNode
32
34
  from .ast import Slice
33
35
  from .ast import Subexpression
36
+ from .ast import UnaryArithmeticOperator
34
37
  from .ast import ValueProjection
35
38
  from .ast import VariableRef
36
39
  from .exceptions import UndefinedVariableError
@@ -164,7 +167,7 @@ class _Expression:
164
167
 
165
168
 
166
169
  class TreeInterpreter(Visitor):
167
- COMPARATOR_FUNC: ta.Mapping[str, ta.Callable] = {
170
+ _COMPARATOR_FUNC: ta.Mapping[ComparatorName, ta.Callable] = {
168
171
  'eq': _equals,
169
172
  'ne': lambda x, y: not _equals(x, y),
170
173
  'lt': operator.lt,
@@ -173,17 +176,12 @@ class TreeInterpreter(Visitor):
173
176
  'gte': operator.ge,
174
177
  }
175
178
 
176
- _EQUALITY_OPS: ta.AbstractSet[str] = {
179
+ _EQUALITY_OPS: ta.AbstractSet[ComparatorName] = {
177
180
  'eq',
178
181
  'ne',
179
182
  }
180
183
 
181
- _ARITHMETIC_UNARY_FUNC: ta.Mapping[str, ta.Callable] = {
182
- 'minus': operator.neg,
183
- 'plus': lambda x: x,
184
- }
185
-
186
- _ARITHMETIC_FUNC: ta.Mapping[str, ta.Callable] = {
184
+ _ARITHMETIC_FUNC: ta.Mapping[ArithmeticOperator, ta.Callable] = {
187
185
  'div': operator.floordiv,
188
186
  'divide': operator.truediv,
189
187
  'minus': operator.sub,
@@ -192,6 +190,11 @@ class TreeInterpreter(Visitor):
192
190
  'plus': operator.add,
193
191
  }
194
192
 
193
+ _ARITHMETIC_UNARY_FUNC: ta.Mapping[UnaryArithmeticOperator, ta.Callable] = {
194
+ 'minus': operator.neg,
195
+ 'plus': lambda x: x,
196
+ }
197
+
195
198
  def __init__(self, options: Options | None = None) -> None:
196
199
  super().__init__()
197
200
 
@@ -235,7 +238,7 @@ class TreeInterpreter(Visitor):
235
238
 
236
239
  def visit_comparator(self, node: Comparator, value: ta.Any) -> ta.Any:
237
240
  # Common case: comparator is == or !=
238
- comparator_func = self.COMPARATOR_FUNC[node.name]
241
+ comparator_func = self._COMPARATOR_FUNC[node.name]
239
242
  if node.name in self._EQUALITY_OPS:
240
243
  return comparator_func(
241
244
  self.visit(node.first, value),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omlish
3
- Version: 0.0.0.dev119
3
+ Version: 0.0.0.dev120
4
4
  Summary: omlish
5
5
  Author: wrmsr
6
6
  License: BSD-3-Clause
@@ -1,5 +1,5 @@
1
1
  omlish/.manifests.json,sha256=CxGnj-UiRPlZgmgWoovDWrOnqpSEmBy_kqA7cdfSA3w,1431
2
- omlish/__about__.py,sha256=cKBa887pzxYkOLw1HFwEiT4g4dP8AxuJQrGNkTmiju8,3352
2
+ omlish/__about__.py,sha256=JGKddDla0hzssCiRfhxitgG_mY-VKslBVWxhzDUU-Fg,3352
3
3
  omlish/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  omlish/argparse.py,sha256=cqKGAqcxuxv_s62z0gq29L9KAvg_3-_rFvXKjVpRJjo,8126
5
5
  omlish/c3.py,sha256=4vogWgwPb8TbNS2KkZxpoWbwjj7MuHG2lQG-hdtkvjI,8062
@@ -370,16 +370,16 @@ omlish/secrets/secrets.py,sha256=cnDGBoPknVxsCN04_gqcJT_7Ebk3iO3VPkRZ2oMjkMw,786
370
370
  omlish/secrets/subprocesses.py,sha256=EcnKlHHtnUMHGrBWXDfu8tv28wlgZx4P4GOiuPW9Vo8,1105
371
371
  omlish/specs/__init__.py,sha256=zZwF8yXTEkSstYtORkDhVLK-_hWU8WOJCuBpognb_NY,118
372
372
  omlish/specs/jmespath/LICENSE,sha256=IH-ZZlZkS8XMkf_ubNVD1aYHQ2l_wd0tmHtXrCcYpRU,1113
373
- omlish/specs/jmespath/__init__.py,sha256=Lz8JO0vP-pwrBtq9Y94y6LrOA7o1u1kCdPmMf_4lJBY,1918
373
+ omlish/specs/jmespath/__init__.py,sha256=MfBlUXNSPq5pRyboMgBk8JoIj0lQo-2TQ6Re7IwGQK0,2079
374
374
  omlish/specs/jmespath/__main__.py,sha256=wIXm6bs08etNG_GZlN2rBkADPb0rKfL2HSkm8spnpxw,200
375
- omlish/specs/jmespath/ast.py,sha256=jiIELiQSHU9haOqXJM4eiSgEapCzHIZ1F-fP_RGpRbk,5019
375
+ omlish/specs/jmespath/ast.py,sha256=XhcUGodHIdsY3-hVZEfpeW6LBehRjLbxVFXkMfZhRdk,5386
376
376
  omlish/specs/jmespath/cli.py,sha256=Lw57Eq5rmpwTwsvOzNmce_-XyoM84OIx5cuPgjUXNb0,2197
377
377
  omlish/specs/jmespath/exceptions.py,sha256=Co1HiUBPFNwFgZY3FV_ayuZoSgZIAmDcImImxauYNxc,4435
378
- omlish/specs/jmespath/functions.py,sha256=DG6wf4m0EuqD2FZnSKOFb4GvuXyCqlbncQvlBUN1NYY,22209
378
+ omlish/specs/jmespath/functions.py,sha256=lE_MlW5rDQirDCE9HtcAG-17kuHhH36RaPaQfk97xDY,22595
379
379
  omlish/specs/jmespath/lexer.py,sha256=hlPGCXPzGhd9ySj-z2cGTbyC9z3e0Io78IMYJZSEwNk,12647
380
- omlish/specs/jmespath/parser.py,sha256=yidV9KzHBsrO4-HJF53AOOxSvtqq5u0DESFaWY_0llA,24256
380
+ omlish/specs/jmespath/parser.py,sha256=IPJ0fCv1Aj2MhsDx5XuddtM2LnnLrynuGs4g7PYCmf0,24453
381
381
  omlish/specs/jmespath/scope.py,sha256=UyDsl9rv_c8DCjJBuVIA2ESu1jrgYvuwEKiaJDQKnT0,1590
382
- omlish/specs/jmespath/visitor.py,sha256=-A386ebMQAJE_vvbGHpQyESu1h0W-PGvaHE5_jgjiH4,16401
382
+ omlish/specs/jmespath/visitor.py,sha256=yneRMO4qf3k2Mdcm2cPC0ozRgOaudzlxRVRGatztJzs,16569
383
383
  omlish/specs/jsonrpc/__init__.py,sha256=E0EogYSKmbj1D-V57tBgPDTyVuD8HosHqVg0Vh1CVwM,416
384
384
  omlish/specs/jsonrpc/errors.py,sha256=-Zgmlo6bV6J8w5f8h9axQgLquIFBHDgIwcpufEH5NsE,707
385
385
  omlish/specs/jsonrpc/marshal.py,sha256=iXZNR7n0vfL_yiPFFYN-ZyGlzknNXExs2qC1HFChGPU,1913
@@ -471,9 +471,9 @@ omlish/text/glyphsplit.py,sha256=Ug-dPRO7x-OrNNr8g1y6DotSZ2KH0S-VcOmUobwa4B0,329
471
471
  omlish/text/indent.py,sha256=6Jj6TFY9unaPa4xPzrnZemJ-fHsV53IamP93XGjSUHs,1274
472
472
  omlish/text/parts.py,sha256=7vPF1aTZdvLVYJ4EwBZVzRSy8XB3YqPd7JwEnNGGAOo,6495
473
473
  omlish/text/random.py,sha256=jNWpqiaKjKyTdMXC-pWAsSC10AAP-cmRRPVhm59ZWLk,194
474
- omlish-0.0.0.dev119.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
475
- omlish-0.0.0.dev119.dist-info/METADATA,sha256=sMg30UlhW1GLNw8MkOhVqMaaiObB2IXCn22KIqaMpWU,4000
476
- omlish-0.0.0.dev119.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
477
- omlish-0.0.0.dev119.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
478
- omlish-0.0.0.dev119.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
479
- omlish-0.0.0.dev119.dist-info/RECORD,,
474
+ omlish-0.0.0.dev120.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
475
+ omlish-0.0.0.dev120.dist-info/METADATA,sha256=9KUQ86p-Od1hMU_EibbqCHSW6pojpLGYyvZCxg935BE,4000
476
+ omlish-0.0.0.dev120.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
477
+ omlish-0.0.0.dev120.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
478
+ omlish-0.0.0.dev120.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
479
+ omlish-0.0.0.dev120.dist-info/RECORD,,