jaclang 0.7.28__py3-none-any.whl → 0.7.29__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of jaclang might be problematic. Click here for more details.

jaclang/plugin/default.py CHANGED
@@ -43,8 +43,11 @@ from jaclang.runtimelib.constructs import (
43
43
  from jaclang.runtimelib.importer import ImportPathSpec, JacImporter, PythonImporter
44
44
  from jaclang.runtimelib.machine import JacMachine, JacProgram
45
45
  from jaclang.runtimelib.memory import Shelf, ShelfStorage
46
- from jaclang.runtimelib.utils import collect_node_connections, traverse_graph
47
-
46
+ from jaclang.runtimelib.utils import (
47
+ all_issubclass,
48
+ collect_node_connections,
49
+ traverse_graph,
50
+ )
48
51
 
49
52
  import pluggy
50
53
 
@@ -399,64 +402,85 @@ class JacWalkerImpl:
399
402
 
400
403
  walker.path = []
401
404
  walker.next = [node]
402
- if walker.next:
403
- current_node = walker.next[-1].architype
404
- for i in warch._jac_entry_funcs_:
405
- trigger = i.get_funcparam_annotations(i.func)
406
- if not trigger:
407
- if i.func:
408
- i.func(warch, current_node)
409
- else:
410
- raise ValueError(f"No function {i.name} to call.")
405
+ current_node = node.architype
406
+
407
+ # walker entry
408
+ for i in warch._jac_entry_funcs_:
409
+ if i.func and not i.trigger:
410
+ i.func(warch, current_node)
411
+ if walker.disengaged:
412
+ return warch
413
+
411
414
  while len(walker.next):
412
415
  if current_node := walker.next.pop(0).architype:
416
+ # walker entry with
417
+ for i in warch._jac_entry_funcs_:
418
+ if (
419
+ i.func
420
+ and i.trigger
421
+ and all_issubclass(i.trigger, NodeArchitype)
422
+ and isinstance(current_node, i.trigger)
423
+ ):
424
+ i.func(warch, current_node)
425
+ if walker.disengaged:
426
+ return warch
427
+
428
+ # node entry
413
429
  for i in current_node._jac_entry_funcs_:
414
- trigger = i.get_funcparam_annotations(i.func)
415
- if not trigger or isinstance(warch, trigger):
416
- if i.func:
417
- i.func(current_node, warch)
418
- else:
419
- raise ValueError(f"No function {i.name} to call.")
430
+ if i.func and not i.trigger:
431
+ i.func(current_node, warch)
420
432
  if walker.disengaged:
421
433
  return warch
422
- for i in warch._jac_entry_funcs_:
423
- trigger = i.get_funcparam_annotations(i.func)
424
- if not trigger or isinstance(current_node, trigger):
425
- if i.func and trigger:
426
- i.func(warch, current_node)
427
- elif not trigger:
428
- continue
429
- else:
430
- raise ValueError(f"No function {i.name} to call.")
434
+
435
+ # node entry with
436
+ for i in current_node._jac_entry_funcs_:
437
+ if (
438
+ i.func
439
+ and i.trigger
440
+ and all_issubclass(i.trigger, WalkerArchitype)
441
+ and isinstance(warch, i.trigger)
442
+ ):
443
+ i.func(current_node, warch)
431
444
  if walker.disengaged:
432
445
  return warch
433
- for i in warch._jac_exit_funcs_:
434
- trigger = i.get_funcparam_annotations(i.func)
435
- if not trigger or isinstance(current_node, trigger):
436
- if i.func and trigger:
437
- i.func(warch, current_node)
438
- elif not trigger:
439
- continue
440
- else:
441
- raise ValueError(f"No function {i.name} to call.")
446
+
447
+ # node exit with
448
+ for i in current_node._jac_exit_funcs_:
449
+ if (
450
+ i.func
451
+ and i.trigger
452
+ and all_issubclass(i.trigger, WalkerArchitype)
453
+ and isinstance(warch, i.trigger)
454
+ ):
455
+ i.func(current_node, warch)
442
456
  if walker.disengaged:
443
457
  return warch
458
+
459
+ # node exit
444
460
  for i in current_node._jac_exit_funcs_:
445
- trigger = i.get_funcparam_annotations(i.func)
446
- if not trigger or isinstance(warch, trigger):
447
- if i.func:
448
- i.func(current_node, warch)
449
- else:
450
- raise ValueError(f"No function {i.name} to call.")
461
+ if i.func and not i.trigger:
462
+ i.func(current_node, warch)
451
463
  if walker.disengaged:
452
464
  return warch
465
+
466
+ # walker exit with
467
+ for i in warch._jac_exit_funcs_:
468
+ if (
469
+ i.func
470
+ and i.trigger
471
+ and all_issubclass(i.trigger, NodeArchitype)
472
+ and isinstance(current_node, i.trigger)
473
+ ):
474
+ i.func(warch, current_node)
475
+ if walker.disengaged:
476
+ return warch
477
+ # walker exit
453
478
  for i in warch._jac_exit_funcs_:
454
- trigger = i.get_funcparam_annotations(i.func)
455
- if not trigger:
456
- if i.func:
457
- i.func(warch, current_node)
458
- else:
459
- raise ValueError(f"No function {i.name} to call.")
479
+ if i.func and not i.trigger:
480
+ i.func(warch, current_node)
481
+ if walker.disengaged:
482
+ return warch
483
+
460
484
  walker.ignores = []
461
485
  return warch
462
486
 
@@ -5,6 +5,7 @@ from __future__ import annotations
5
5
  import inspect
6
6
  from dataclasses import asdict, dataclass, field, fields, is_dataclass
7
7
  from enum import IntEnum
8
+ from functools import cached_property
8
9
  from logging import getLogger
9
10
  from pickle import dumps
10
11
  from types import UnionType
@@ -220,9 +221,9 @@ class WalkerAnchor(Anchor):
220
221
  """Walker Anchor."""
221
222
 
222
223
  architype: WalkerArchitype
223
- path: list[Anchor] = field(default_factory=list)
224
- next: list[Anchor] = field(default_factory=list)
225
- ignores: list[Anchor] = field(default_factory=list)
224
+ path: list[NodeAnchor] = field(default_factory=list)
225
+ next: list[NodeAnchor] = field(default_factory=list)
226
+ ignores: list[NodeAnchor] = field(default_factory=list)
226
227
  disengaged: bool = False
227
228
 
228
229
 
@@ -311,17 +312,20 @@ class DSFunc:
311
312
  name: str
312
313
  func: Callable[[Any, Any], Any] | None = None
313
314
 
315
+ @cached_property
316
+ def trigger(self) -> type | UnionType | tuple[type | UnionType, ...] | None:
317
+ """Get function parameter annotations."""
318
+ t = (
319
+ (
320
+ inspect.signature(self.func, eval_str=True)
321
+ .parameters["_jac_here_"]
322
+ .annotation
323
+ )
324
+ if self.func
325
+ else None
326
+ )
327
+ return None if t is inspect._empty else t
328
+
314
329
  def resolve(self, cls: type) -> None:
315
330
  """Resolve the function."""
316
331
  self.func = getattr(cls, self.name)
317
-
318
- def get_funcparam_annotations(
319
- self, func: Callable[[Any, Any], Any] | None
320
- ) -> type | UnionType | tuple[type | UnionType, ...] | None:
321
- """Get function parameter annotations."""
322
- if not func:
323
- return None
324
- annotation = (
325
- inspect.signature(func, eval_str=True).parameters["_jac_here_"].annotation
326
- )
327
- return annotation if annotation != inspect._empty else None
@@ -231,3 +231,18 @@ def is_instance(
231
231
  return isinstance(obj, target)
232
232
  case _:
233
233
  return False
234
+
235
+
236
+ def all_issubclass(
237
+ classes: type | UnionType | tuple[type | UnionType, ...], target: type
238
+ ) -> bool:
239
+ """Check if all classes is subclass of target type."""
240
+ match classes:
241
+ case type():
242
+ return issubclass(classes, target)
243
+ case UnionType():
244
+ return all((all_issubclass(cls, target) for cls in classes.__args__))
245
+ case tuple():
246
+ return all((all_issubclass(cls, target) for cls in classes))
247
+ case _:
248
+ return False
@@ -0,0 +1,50 @@
1
+ node Node {
2
+ has val: str;
3
+
4
+ can entry1 with entry {
5
+ print(f"{self.val}-2");
6
+ }
7
+
8
+ can entry2 with Walker entry {
9
+ print(f"{self.val}-3");
10
+ }
11
+
12
+ can exit1 with Walker exit {
13
+ print(f"{self.val}-4");
14
+ }
15
+
16
+ can exit2 with exit {
17
+ print(f"{self.val}-5");
18
+ }
19
+ }
20
+
21
+ walker Walker {
22
+ can entry1 with entry {
23
+ print("walker entry");
24
+ }
25
+
26
+ can entry2 with `root entry {
27
+ print("walker enter to root");
28
+ visit [-->];
29
+ }
30
+
31
+ can entry3 with Node entry {
32
+ print(f"{here.val}-1");
33
+ }
34
+
35
+ can exit1 with Node exit {
36
+ print(f"{here.val}-6");
37
+ }
38
+
39
+ can exit2 with exit {
40
+ print("walker exit");
41
+ }
42
+ }
43
+
44
+ with entry{
45
+ root ++> Node(val = "a");
46
+ root ++> Node(val = "b");
47
+ root ++> Node(val = "c");
48
+
49
+ Walker() spawn root;
50
+ }
@@ -1230,5 +1230,20 @@ class JacLanguageTests(TestCase):
1230
1230
  jac_import("architype_def_bug", base_path=self.fixture_abs_path("./"))
1231
1231
  sys.stdout = sys.__stdout__
1232
1232
  stdout_value = captured_output.getvalue().split("\n")
1233
- self.assertIn("MyNode", stdout_value[0])
1234
- self.assertIn("MyWalker", stdout_value[1])
1233
+ self.assertIn("MyWalker", stdout_value[0])
1234
+ self.assertIn("MyNode", stdout_value[1])
1235
+
1236
+ def test_visit_sequence(self) -> None:
1237
+ """Test conn assign on edges."""
1238
+ captured_output = io.StringIO()
1239
+ sys.stdout = captured_output
1240
+ jac_import("visit_sequence", base_path=self.fixture_abs_path("./"))
1241
+ sys.stdout = sys.__stdout__
1242
+ self.assertEqual(
1243
+ "walker entry\nwalker enter to root\n"
1244
+ "a-1\na-2\na-3\na-4\na-5\na-6\n"
1245
+ "b-1\nb-2\nb-3\nb-4\nb-5\nb-6\n"
1246
+ "c-1\nc-2\nc-3\nc-4\nc-5\nc-6\n"
1247
+ "walker exit\n",
1248
+ captured_output.getvalue(),
1249
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: jaclang
3
- Version: 0.7.28
3
+ Version: 0.7.29
4
4
  Summary: Jac is a unique and powerful programming language that runs on top of Python, offering an unprecedented level of intelligence and intuitive understanding.
5
5
  Home-page: https://jaseci.org
6
6
  License: MIT
@@ -169,7 +169,7 @@ jaclang/langserve/tests/test_server.py,sha256=Z-RXNuCXFPi67uXkW1hmoJmrb37VFRpRdH
169
169
  jaclang/langserve/utils.py,sha256=edZCrq8ZFolao-rvv5RGPxtnEh6NmhrxOgPh8VxmEPs,15019
170
170
  jaclang/plugin/__init__.py,sha256=5t2krHKt_44PrCTGojzxEimxpNHYVQcn89jAiCSXE_k,165
171
171
  jaclang/plugin/builtin.py,sha256=zNTbe5knJrGFgJRa4l4hMzzuij6iXFyVqRTxputUHIo,1307
172
- jaclang/plugin/default.py,sha256=ufEhllQ19UIDnPFsbZRgL_f_uMjc_0tL4yltO9y01ok,47303
172
+ jaclang/plugin/default.py,sha256=SzdXIqkbRjFfTJkm2ZBrfMcZ3yyWtF-m6DA5pMWPJww,47451
173
173
  jaclang/plugin/feature.py,sha256=MwTG38T0kyCAUiZd_dKFLu4eW6lYKn7LDUObv-iBc1k,17178
174
174
  jaclang/plugin/plugin.md,sha256=B252QTH3c8uZyvXTbGmZBafZtdXstFC5vT5jIN_gS4U,9994
175
175
  jaclang/plugin/spec.py,sha256=c6Syscbo38eDOLfx34YaIa5lW0PUjIc9lgFtEtRBVzg,14748
@@ -185,14 +185,14 @@ jaclang/plugin/tests/test_features.py,sha256=sK9d2UazofGl9qYZO_ODKmOHZY8E4fnXNoy
185
185
  jaclang/plugin/tests/test_jaseci.py,sha256=g2HQWPaG4E2FQOWcKmZ2SM2MDDOEy2s1u14Idb7GTbw,27398
186
186
  jaclang/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
187
187
  jaclang/runtimelib/__init__.py,sha256=jDDYBCV82qPhmcDVk3NIvHbhng0ebSrXD3xrojg0-eo,34
188
- jaclang/runtimelib/architype.py,sha256=Egw3hmLDAt_jxQBagT_WoLv5Evl7hUbGkPx0-skboLw,8650
188
+ jaclang/runtimelib/architype.py,sha256=oKwDKH-uy3l1z7Z89jF0l2rZHmtZ0eu-OBC6kcvE8qA,8695
189
189
  jaclang/runtimelib/constructs.py,sha256=1ARnsPrDi1UvyaFRhGRhO0kj0fnIZ2HbHF7O3itB-ZQ,796
190
190
  jaclang/runtimelib/context.py,sha256=DjCkj1S6WLBWbNMkhUjqPYIhxqXV0XjJ1Mpjy7WR4g0,5538
191
191
  jaclang/runtimelib/importer.py,sha256=a6ORKrDfK-jKXopgyZHz188O-VI2NflFQo7VTUVvqOw,14592
192
192
  jaclang/runtimelib/machine.py,sha256=8gyGLxURqfy0bLXMWyOwjIX-rH8Mz11b-jV6Ta5liTk,11566
193
193
  jaclang/runtimelib/memory.py,sha256=LrVTo6Cac0q-YG1wug-Fgc8O2Tue9zRHnxSulDw3ZQ4,5656
194
194
  jaclang/runtimelib/test.py,sha256=4HW7MjHmxjwWjwtIqLtFpcq9B9rI4NmyA92qFy9yhz8,4709
195
- jaclang/runtimelib/utils.py,sha256=xcxO45lEwEBRrWeeAaRjqGZ4Ua-XMCeNv0lS6dHwGIk,8652
195
+ jaclang/runtimelib/utils.py,sha256=6_fLmG3zfcX7cVKCq_NvkGjsDsx1nxvV_1GLpyIp8IY,9150
196
196
  jaclang/settings.py,sha256=1oxaHpRfrjuwtwgoRJl-abxb8qlvIXUf0JqE-apLLqo,3793
197
197
  jaclang/tests/fixtures/abc.jac,sha256=HZvLz6IEt3Snlgg8Czs-N4emLjg4fT3IbTo95d3Gdww,1747
198
198
  jaclang/tests/fixtures/access_checker.jac,sha256=UVoY7sYW-R0ms2HDA4HXQ5xJNiW0vEbY2T5CCY1avus,281
@@ -310,6 +310,7 @@ jaclang/tests/fixtures/tupleunpack.jac,sha256=AP6rbofc0VmsTNxInY6WLGRKWVY6u8ut0u
310
310
  jaclang/tests/fixtures/tuplytuples.jac,sha256=6qiXn5OV_qn4cqKwROjJ1VuBAh0nbUGpp-5vtH9n_Dg,344
311
311
  jaclang/tests/fixtures/type_info.jac,sha256=4Cw31ef5gny6IS0kLzgeSO-7ArEH1HgFFFip1BGQhZM,316
312
312
  jaclang/tests/fixtures/visit_order.jac,sha256=5_U-sJX_TkY9A1ho4ibCr-53pFYRtkl97FfMlhoke3w,260
313
+ jaclang/tests/fixtures/visit_sequence.jac,sha256=My5EdoMMc-6kSKtIuVQLTQ9bmiyfZb1xAyLvd5KH1CQ,830
313
314
  jaclang/tests/fixtures/walker_override.jac,sha256=Ok58ZAgxuV6aECNxYrjbbyAWSiqIbnly3N3O6cD563o,271
314
315
  jaclang/tests/fixtures/walker_update.jac,sha256=_bN3ASAN6LpfIQFfDMRnrx2oteM-ef7OrbE91f2qvrs,463
315
316
  jaclang/tests/fixtures/with_context.jac,sha256=cDA_4YWe5UVmQRgcpktzkZ_zsswQpV_T2Otf_rFnPy8,466
@@ -317,7 +318,7 @@ jaclang/tests/foo/__init__.jac,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
317
318
  jaclang/tests/main.jac,sha256=UJ4dASLCMA3wW78Rq3AHcq5GfXVY5QBm2S16OCrR1hQ,13
318
319
  jaclang/tests/test_bugs.py,sha256=tBPsIlSPqZDIz4QaScNRT-WdGIdJ0uU-aRBWq1XUZ6o,555
319
320
  jaclang/tests/test_cli.py,sha256=jADI7iZN7PguCzmtAt0oK1RZkboRFKjHfz-fN5rC78w,19332
320
- jaclang/tests/test_language.py,sha256=e92KDCXtP9myt4nvA7iCzBUq6V4zjbkro39vW1Lrh6U,50423
321
+ jaclang/tests/test_language.py,sha256=s4phFcN1lK_OdpjhWq2bpzHC4s58Djjsn6REeHV4sRU,50988
321
322
  jaclang/tests/test_man_code.py,sha256=ZdNarlZVfT_-8Jv3FjLplHw76tsvkCuISyfX3M4qxPg,5027
322
323
  jaclang/tests/test_reference.py,sha256=FISQpZbB8cmRoAeJOFfXUy13WVxykZjpkPSb1OTotfI,3340
323
324
  jaclang/tests/test_settings.py,sha256=TIX5uiu8H9IpZN2__uFiclcdCpBpPpcAwtlEHyFC4kk,1999
@@ -1551,7 +1552,7 @@ jaclang/vendor/typing_extensions-4.12.2.dist-info/METADATA,sha256=BeUQIa8cnYbrjW
1551
1552
  jaclang/vendor/typing_extensions-4.12.2.dist-info/RECORD,sha256=XS4fBVrPI7kaNZ56Ggl2RGa76jySWLqTzcrUpZIQTVM,418
1552
1553
  jaclang/vendor/typing_extensions-4.12.2.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
1553
1554
  jaclang/vendor/typing_extensions.py,sha256=gwekpyG9DVG3lxWKX4ni8u7nk3We5slG98mA9F3DJQw,134451
1554
- jaclang-0.7.28.dist-info/METADATA,sha256=dHW7qbjtqZqrcvGQYgK25k01-zfa7pnliEAzqyBB1BA,4965
1555
- jaclang-0.7.28.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
1556
- jaclang-0.7.28.dist-info/entry_points.txt,sha256=8sMi4Tvi9f8tQDN2QAXsSA2icO27zQ4GgEdph6bNEZM,49
1557
- jaclang-0.7.28.dist-info/RECORD,,
1555
+ jaclang-0.7.29.dist-info/METADATA,sha256=qzaiCwzH5P2Ahvt6GUeAYJQjmB4TWY7a1hVlL9YHVkc,4965
1556
+ jaclang-0.7.29.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
1557
+ jaclang-0.7.29.dist-info/entry_points.txt,sha256=8sMi4Tvi9f8tQDN2QAXsSA2icO27zQ4GgEdph6bNEZM,49
1558
+ jaclang-0.7.29.dist-info/RECORD,,