jaclang 0.7.14__py3-none-any.whl → 0.7.17__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.

Files changed (131) hide show
  1. jaclang/cli/cli.py +147 -77
  2. jaclang/cli/cmdreg.py +9 -12
  3. jaclang/compiler/__init__.py +19 -53
  4. jaclang/compiler/absyntree.py +94 -16
  5. jaclang/compiler/constant.py +8 -8
  6. jaclang/compiler/jac.lark +4 -3
  7. jaclang/compiler/parser.py +41 -25
  8. jaclang/compiler/passes/ir_pass.py +4 -13
  9. jaclang/compiler/passes/main/__init__.py +1 -1
  10. jaclang/compiler/passes/main/access_modifier_pass.py +96 -147
  11. jaclang/compiler/passes/main/fuse_typeinfo_pass.py +155 -54
  12. jaclang/compiler/passes/main/import_pass.py +99 -75
  13. jaclang/compiler/passes/main/py_collect_dep_pass.py +70 -0
  14. jaclang/compiler/passes/main/pyast_gen_pass.py +328 -565
  15. jaclang/compiler/passes/main/pyast_load_pass.py +33 -6
  16. jaclang/compiler/passes/main/pyjac_ast_link_pass.py +7 -0
  17. jaclang/compiler/passes/main/registry_pass.py +37 -3
  18. jaclang/compiler/passes/main/schedules.py +9 -2
  19. jaclang/compiler/passes/main/sym_tab_build_pass.py +10 -6
  20. jaclang/compiler/passes/main/tests/__init__.py +1 -1
  21. jaclang/compiler/passes/main/tests/fixtures/autoimpl.empty.impl.jac +0 -0
  22. jaclang/compiler/passes/main/tests/fixtures/autoimpl.jac +1 -1
  23. jaclang/compiler/passes/main/tests/fixtures/py_imp_test.jac +29 -0
  24. jaclang/compiler/passes/main/tests/fixtures/pygame_mock/__init__.py +3 -0
  25. jaclang/compiler/passes/main/tests/fixtures/pygame_mock/color.py +3 -0
  26. jaclang/compiler/passes/main/tests/fixtures/pygame_mock/constants.py +5 -0
  27. jaclang/compiler/passes/main/tests/fixtures/pygame_mock/display.py +2 -0
  28. jaclang/compiler/passes/main/tests/test_import_pass.py +72 -13
  29. jaclang/compiler/passes/main/type_check_pass.py +22 -5
  30. jaclang/compiler/passes/tool/jac_formatter_pass.py +135 -89
  31. jaclang/compiler/passes/tool/tests/fixtures/corelib.jac +37 -41
  32. jaclang/compiler/passes/tool/tests/fixtures/corelib_fmt.jac +37 -42
  33. jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/access_mod_check.jac +27 -0
  34. jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/architype_test.jac +13 -0
  35. jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/comment_alignment.jac +11 -0
  36. jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/comments.jac +13 -0
  37. jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/decorator_stack.jac +37 -0
  38. jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/esc_keywords.jac +5 -0
  39. jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/long_names.jac +19 -0
  40. jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/triple_quoted_string.jac +6 -0
  41. jaclang/compiler/passes/tool/tests/test_jac_format_pass.py +11 -0
  42. jaclang/compiler/passes/tool/tests/test_unparse_validate.py +33 -39
  43. jaclang/compiler/passes/transform.py +4 -0
  44. jaclang/compiler/passes/utils/mypy_ast_build.py +45 -0
  45. jaclang/compiler/semtable.py +31 -7
  46. jaclang/compiler/symtable.py +16 -11
  47. jaclang/compiler/tests/test_importer.py +25 -10
  48. jaclang/langserve/engine.py +104 -118
  49. jaclang/langserve/sem_manager.py +379 -0
  50. jaclang/langserve/server.py +24 -11
  51. jaclang/langserve/tests/fixtures/base_module_structure.jac +27 -6
  52. jaclang/langserve/tests/fixtures/circle.jac +3 -3
  53. jaclang/langserve/tests/fixtures/circle_err.jac +3 -3
  54. jaclang/langserve/tests/fixtures/circle_pure.test.jac +3 -3
  55. jaclang/langserve/tests/fixtures/import_include_statements.jac +1 -1
  56. jaclang/langserve/tests/fixtures/rename.jac +30 -0
  57. jaclang/langserve/tests/test_sem_tokens.py +277 -0
  58. jaclang/langserve/tests/test_server.py +287 -17
  59. jaclang/langserve/utils.py +184 -98
  60. jaclang/plugin/builtin.py +1 -1
  61. jaclang/plugin/default.py +288 -92
  62. jaclang/plugin/feature.py +65 -27
  63. jaclang/plugin/spec.py +62 -23
  64. jaclang/plugin/tests/fixtures/other_root_access.jac +82 -0
  65. jaclang/plugin/tests/test_jaseci.py +414 -42
  66. jaclang/runtimelib/architype.py +650 -0
  67. jaclang/{core → runtimelib}/constructs.py +5 -8
  68. jaclang/{core → runtimelib}/context.py +86 -59
  69. jaclang/runtimelib/importer.py +361 -0
  70. jaclang/runtimelib/machine.py +158 -0
  71. jaclang/runtimelib/memory.py +158 -0
  72. jaclang/{core → runtimelib}/utils.py +30 -15
  73. jaclang/settings.py +5 -4
  74. jaclang/tests/fixtures/abc.jac +3 -3
  75. jaclang/tests/fixtures/access_checker.jac +12 -17
  76. jaclang/tests/fixtures/access_modifier.jac +88 -33
  77. jaclang/tests/fixtures/baddy.jac +3 -0
  78. jaclang/tests/fixtures/baddy.test.jac +3 -0
  79. jaclang/tests/fixtures/bar.jac +34 -0
  80. jaclang/tests/fixtures/byllmissue.jac +1 -5
  81. jaclang/tests/fixtures/chandra_bugs2.jac +11 -10
  82. jaclang/tests/fixtures/cls_method.jac +41 -0
  83. jaclang/tests/fixtures/dblhello.jac +6 -0
  84. jaclang/tests/fixtures/deep/one_lev.jac +3 -3
  85. jaclang/tests/fixtures/deep/one_lev_dup.jac +2 -3
  86. jaclang/tests/fixtures/deep_import_mods.jac +13 -0
  87. jaclang/tests/fixtures/edge_node_walk.jac +1 -1
  88. jaclang/tests/fixtures/edge_ops.jac +1 -1
  89. jaclang/tests/fixtures/edges_walk.jac +1 -1
  90. jaclang/tests/fixtures/err.impl.jac +3 -0
  91. jaclang/tests/fixtures/err.jac +4 -2
  92. jaclang/tests/fixtures/err_runtime.jac +15 -0
  93. jaclang/tests/fixtures/foo.jac +43 -0
  94. jaclang/tests/fixtures/gendot_bubble_sort.jac +1 -1
  95. jaclang/tests/fixtures/hello.jac +4 -0
  96. jaclang/tests/fixtures/impl_grab.impl.jac +2 -1
  97. jaclang/tests/fixtures/impl_grab.jac +4 -1
  98. jaclang/tests/fixtures/import.jac +9 -0
  99. jaclang/tests/fixtures/index_slice.jac +30 -0
  100. jaclang/tests/fixtures/jp_importer_auto.jac +14 -0
  101. jaclang/tests/fixtures/maxfail_run_test.jac +4 -4
  102. jaclang/tests/fixtures/needs_import.jac +2 -2
  103. jaclang/tests/fixtures/pyfunc_1.py +1 -1
  104. jaclang/tests/fixtures/pyfunc_2.py +5 -2
  105. jaclang/tests/fixtures/pygame_mock/__init__.py +3 -0
  106. jaclang/tests/fixtures/pygame_mock/color.py +3 -0
  107. jaclang/tests/fixtures/pygame_mock/constants.py +5 -0
  108. jaclang/tests/fixtures/pygame_mock/display.py +2 -0
  109. jaclang/tests/fixtures/pygame_mock/inner/__init__.py +0 -0
  110. jaclang/tests/fixtures/pygame_mock/inner/iner_mod.py +2 -0
  111. jaclang/tests/fixtures/registry.jac +9 -0
  112. jaclang/tests/fixtures/run_test.jac +4 -4
  113. jaclang/tests/fixtures/semstr.jac +1 -4
  114. jaclang/tests/fixtures/simple_archs.jac +1 -1
  115. jaclang/tests/test_cli.py +109 -3
  116. jaclang/tests/test_language.py +170 -68
  117. jaclang/tests/test_reference.py +2 -3
  118. jaclang/utils/helpers.py +45 -21
  119. jaclang/utils/test.py +9 -0
  120. jaclang/utils/treeprinter.py +30 -7
  121. {jaclang-0.7.14.dist-info → jaclang-0.7.17.dist-info}/METADATA +3 -2
  122. {jaclang-0.7.14.dist-info → jaclang-0.7.17.dist-info}/RECORD +126 -90
  123. jaclang/core/architype.py +0 -502
  124. jaclang/core/importer.py +0 -344
  125. jaclang/core/memory.py +0 -99
  126. jaclang/tests/fixtures/aott_raise.jac +0 -25
  127. jaclang/tests/fixtures/package_import.jac +0 -6
  128. /jaclang/{core → runtimelib}/__init__.py +0 -0
  129. /jaclang/{core → runtimelib}/test.py +0 -0
  130. {jaclang-0.7.14.dist-info → jaclang-0.7.17.dist-info}/WHEEL +0 -0
  131. {jaclang-0.7.14.dist-info → jaclang-0.7.17.dist-info}/entry_points.txt +0 -0
jaclang/core/importer.py DELETED
@@ -1,344 +0,0 @@
1
- """Special Imports for Jac Code."""
2
-
3
- import importlib
4
- import marshal
5
- import os
6
- import sys
7
- import types
8
- from os import getcwd, path
9
- from typing import Optional, Union
10
-
11
- from jaclang.compiler.absyntree import Module
12
- from jaclang.compiler.compile import compile_jac
13
- from jaclang.compiler.constant import Constants as Con
14
- from jaclang.core.utils import sys_path_context
15
-
16
-
17
- def handle_directory(
18
- module_name: str, full_mod_path: str, mod_bundle: Optional[Module]
19
- ) -> types.ModuleType:
20
- """Import from a directory that potentially contains multiple Jac modules."""
21
- module = types.ModuleType(module_name)
22
- module.__name__ = module_name
23
- module.__path__ = [full_mod_path]
24
- module.__file__ = None
25
- module.__dict__["__jac_mod_bundle__"] = mod_bundle
26
- if module_name not in sys.modules:
27
- sys.modules[module_name] = module
28
- return module
29
-
30
-
31
- def process_items(
32
- module: types.ModuleType,
33
- items: dict[str, Union[str, Optional[str]]],
34
- caller_dir: str,
35
- lang: Optional[str],
36
- mod_bundle: Optional[Module] = None,
37
- cachable: bool = True,
38
- ) -> list:
39
- """Process items within a module by handling renaming and potentially loading missing attributes."""
40
- unique_loaded_items = []
41
-
42
- def handle_item_loading(item: str, alias: Union[str, Optional[str]]) -> None:
43
- if item:
44
- unique_loaded_items.append(item)
45
- setattr(module, name, item)
46
- if alias and alias != name and not isinstance(alias, bool):
47
- setattr(module, alias, item)
48
-
49
- for name, alias in items.items():
50
- try:
51
- item = getattr(module, name)
52
- handle_item_loading(item, alias)
53
- except AttributeError:
54
- if lang == "jac":
55
- jac_file_path = (
56
- os.path.join(module.__path__[0], f"{name}.jac")
57
- if hasattr(module, "__path__")
58
- else module.__file__
59
- )
60
- if jac_file_path and os.path.isfile(jac_file_path):
61
- item = load_jac_file(
62
- module=module,
63
- name=name,
64
- jac_file_path=jac_file_path,
65
- mod_bundle=mod_bundle,
66
- cachable=cachable,
67
- caller_dir=caller_dir,
68
- )
69
- handle_item_loading(item, alias)
70
- elif jac_file_path and os.path.isdir(jac_file_path[:-4]):
71
- item = handle_directory(name, jac_file_path[:-4], mod_bundle)
72
- handle_item_loading(item, alias)
73
- else:
74
- if hasattr(module, "__path__"):
75
- full_module_name = f"{module.__name__}.{name}"
76
- item = importlib.import_module(full_module_name)
77
- handle_item_loading(item, alias)
78
- return unique_loaded_items
79
-
80
-
81
- def load_jac_file(
82
- module: types.ModuleType,
83
- name: str,
84
- jac_file_path: str,
85
- mod_bundle: Optional[Module],
86
- cachable: bool,
87
- caller_dir: str,
88
- ) -> Optional[types.ModuleType]:
89
- """Load a single .jac file into the specified module component."""
90
- try:
91
- package_name = (
92
- f"{module.__name__}.{name}"
93
- if hasattr(module, "__path__")
94
- else module.__name__
95
- )
96
- new_module = sys.modules.get(
97
- package_name,
98
- create_jac_py_module(mod_bundle, name, module.__name__, jac_file_path),
99
- )
100
-
101
- codeobj = get_codeobj(
102
- full_target=jac_file_path,
103
- module_name=name,
104
- mod_bundle=mod_bundle,
105
- cachable=cachable,
106
- caller_dir=caller_dir,
107
- )
108
- if not codeobj:
109
- raise ImportError(f"No bytecode found for {jac_file_path}")
110
-
111
- exec(codeobj, new_module.__dict__)
112
- return getattr(new_module, name, new_module)
113
- except ImportError as e:
114
- print(
115
- f"Failed to load {name} from {jac_file_path} in {module.__name__}: {str(e)}"
116
- )
117
- return None
118
-
119
-
120
- def get_codeobj(
121
- full_target: str,
122
- module_name: str,
123
- mod_bundle: Optional[Module],
124
- cachable: bool,
125
- caller_dir: str,
126
- ) -> Optional[types.CodeType]:
127
- """Execcutes the code for a given module."""
128
- if mod_bundle:
129
- codeobj = mod_bundle.mod_deps[full_target].gen.py_bytecode
130
- return marshal.loads(codeobj) if isinstance(codeobj, bytes) else None
131
- gen_dir = os.path.join(caller_dir, Con.JAC_GEN_DIR)
132
- pyc_file_path = os.path.join(gen_dir, module_name + ".jbc")
133
- if cachable and os.path.exists(pyc_file_path):
134
- with open(pyc_file_path, "rb") as f:
135
- return marshal.load(f)
136
-
137
- result = compile_jac(full_target, cache_result=cachable)
138
- if result.errors_had or not result.ir.gen.py_bytecode:
139
- for e in result.errors_had:
140
- print(e)
141
- return None
142
- if result.ir.gen.py_bytecode is not None:
143
- return marshal.loads(result.ir.gen.py_bytecode)
144
- else:
145
- return None
146
-
147
-
148
- def jac_importer(
149
- target: str,
150
- base_path: str,
151
- absorb: bool = False,
152
- cachable: bool = True,
153
- mdl_alias: Optional[str] = None,
154
- override_name: Optional[str] = None,
155
- mod_bundle: Optional[Module | str] = None,
156
- lng: Optional[str] = "jac",
157
- items: Optional[dict[str, Union[str, Optional[str]]]] = None,
158
- ) -> tuple[types.ModuleType, ...]:
159
- """Core Import Process."""
160
- unique_loaded_items = []
161
- dir_path, file_name = path.split(path.join(*(target.split("."))))
162
- module_name = path.splitext(file_name)[0]
163
- package_path = dir_path.replace(path.sep, ".")
164
- if (
165
- not override_name
166
- and package_path
167
- and f"{package_path}.{module_name}" in sys.modules
168
- ):
169
- module = sys.modules[f"{package_path}.{module_name}"]
170
- elif not override_name and not package_path and module_name in sys.modules:
171
- module = sys.modules[module_name]
172
- else:
173
- module = None
174
- valid_mod_bundle = (
175
- sys.modules[mod_bundle].__jac_mod_bundle__
176
- if isinstance(mod_bundle, str)
177
- and mod_bundle in sys.modules
178
- and "__jac_mod_bundle__" in sys.modules[mod_bundle].__dict__
179
- else None
180
- )
181
-
182
- caller_dir = get_caller_dir(target, base_path, dir_path)
183
- full_target = path.normpath(path.join(caller_dir, file_name))
184
- if not module:
185
- if os.path.isdir(full_target):
186
- module = handle_directory(module_name, full_target, valid_mod_bundle)
187
- else:
188
- full_target += ".jac" if lng == "jac" else ".py"
189
- module_name = path.splitext(file_name)[0]
190
- package_path = dir_path.replace(path.sep, ".")
191
-
192
- if lng == "py":
193
- module, *unique_loaded_items = py_import(
194
- target=target,
195
- items=items,
196
- absorb=absorb,
197
- mdl_alias=mdl_alias,
198
- caller_dir=caller_dir,
199
- )
200
- else:
201
- module_name = override_name if override_name else module_name
202
- module = create_jac_py_module(
203
- valid_mod_bundle,
204
- module_name,
205
- package_path,
206
- full_target,
207
- )
208
- codeobj = get_codeobj(
209
- full_target,
210
- module_name,
211
- valid_mod_bundle,
212
- cachable,
213
- caller_dir=caller_dir,
214
- )
215
- try:
216
- if not codeobj:
217
- raise ImportError(f"No bytecode found for {full_target}")
218
- with sys_path_context(caller_dir):
219
- exec(codeobj, module.__dict__)
220
- except Exception as e:
221
- raise ImportError(f"Error importing {full_target}: {str(e)}")
222
- unique_loaded_items = (
223
- process_items(
224
- module=module,
225
- items=items,
226
- caller_dir=caller_dir,
227
- mod_bundle=valid_mod_bundle,
228
- cachable=cachable,
229
- lang=lng,
230
- )
231
- if items
232
- else []
233
- )
234
- return (module,) if absorb or not items else tuple(unique_loaded_items)
235
-
236
-
237
- def create_jac_py_module(
238
- mod_bundle: Optional[Module],
239
- module_name: str,
240
- package_path: str,
241
- full_target: str,
242
- ) -> types.ModuleType:
243
- """Create a module."""
244
- module = types.ModuleType(module_name)
245
- module.__file__ = full_target
246
- module.__name__ = module_name
247
- module.__dict__["__jac_mod_bundle__"] = mod_bundle
248
- if package_path:
249
- parts = package_path.split(".")
250
- base_path = full_target.split(package_path.replace(".", path.sep))[0]
251
- for i in range(len(parts)):
252
- package_name = ".".join(parts[: i + 1])
253
- if package_name not in sys.modules:
254
- full_mod_path = path.join(
255
- base_path, package_name.replace(".", path.sep)
256
- )
257
- handle_directory(
258
- module_name=package_name,
259
- full_mod_path=full_mod_path,
260
- mod_bundle=mod_bundle,
261
- )
262
-
263
- setattr(sys.modules[package_path], module_name, module)
264
- sys.modules[f"{package_path}.{module_name}"] = module
265
- sys.modules[module_name] = module
266
- return module
267
-
268
-
269
- def get_caller_dir(target: str, base_path: str, dir_path: str) -> str:
270
- """Get the directory of the caller."""
271
- caller_dir = base_path if path.isdir(base_path) else path.dirname(base_path)
272
- caller_dir = caller_dir if caller_dir else getcwd()
273
- chomp_target = target
274
- if chomp_target.startswith("."):
275
- chomp_target = chomp_target[1:]
276
- while chomp_target.startswith("."):
277
- caller_dir = path.dirname(caller_dir)
278
- chomp_target = chomp_target[1:]
279
- caller_dir = path.join(caller_dir, dir_path)
280
- return caller_dir
281
-
282
-
283
- def py_import(
284
- target: str,
285
- caller_dir: str,
286
- items: Optional[dict[str, Union[str, Optional[str]]]] = None,
287
- absorb: bool = False,
288
- mdl_alias: Optional[str] = None,
289
- ) -> tuple[types.ModuleType, ...]:
290
- """Import a Python module."""
291
- try:
292
- loaded_items: list = []
293
- if target.startswith("."):
294
- target = target.lstrip(".")
295
- full_target = path.normpath(path.join(caller_dir, target))
296
- spec = importlib.util.spec_from_file_location(target, full_target + ".py")
297
- if spec and spec.loader:
298
- imported_module = importlib.util.module_from_spec(spec)
299
- sys.modules[spec.name] = imported_module
300
- spec.loader.exec_module(imported_module)
301
- else:
302
- raise ImportError(f"Cannot find module {target} at {full_target}")
303
- else:
304
- imported_module = importlib.import_module(name=target)
305
- main_module = __import__("__main__")
306
- if absorb:
307
- for name in dir(imported_module):
308
- if not name.startswith("_"):
309
- setattr(main_module, name, getattr(imported_module, name))
310
-
311
- elif items:
312
- for name, alias in items.items():
313
- if isinstance(alias, bool):
314
- alias = name
315
- try:
316
- item = getattr(imported_module, name)
317
- if item not in loaded_items:
318
- setattr(
319
- main_module, alias if isinstance(alias, str) else name, item
320
- )
321
- loaded_items.append(item)
322
- except AttributeError as e:
323
- if hasattr(imported_module, "__path__"):
324
- item = importlib.import_module(f"{target}.{name}")
325
- if item not in loaded_items:
326
- setattr(
327
- main_module,
328
- alias if isinstance(alias, str) else name,
329
- item,
330
- )
331
- loaded_items.append(item)
332
- else:
333
- raise e
334
-
335
- else:
336
- setattr(
337
- __import__("__main__"),
338
- mdl_alias if isinstance(mdl_alias, str) else target,
339
- imported_module,
340
- )
341
- return (imported_module, *loaded_items)
342
-
343
- except ImportError as e:
344
- raise e
jaclang/core/memory.py DELETED
@@ -1,99 +0,0 @@
1
- """Core constructs for Jac Language."""
2
-
3
- from __future__ import annotations
4
-
5
- import shelve
6
- from uuid import UUID
7
-
8
- from .architype import Architype
9
-
10
-
11
- class Memory:
12
- """Memory module interface."""
13
-
14
- mem: dict[UUID, Architype] = {}
15
- save_obj_list: dict[UUID, Architype] = {}
16
-
17
- def __init__(self) -> None:
18
- """init."""
19
- pass
20
-
21
- def get_obj(self, obj_id: UUID) -> Architype | None:
22
- """Get object from memory."""
23
- return self.get_obj_from_store(obj_id)
24
-
25
- def get_obj_from_store(self, obj_id: UUID) -> Architype | None:
26
- """Get object from the underlying store."""
27
- ret = self.mem.get(obj_id)
28
- return ret
29
-
30
- def has_obj(self, obj_id: UUID) -> bool:
31
- """Check if the object exists."""
32
- return self.has_obj_in_store(obj_id)
33
-
34
- def has_obj_in_store(self, obj_id: UUID) -> bool:
35
- """Check if the object exists in the underlying store."""
36
- return obj_id in self.mem
37
-
38
- def save_obj(self, item: Architype, persistent: bool) -> None:
39
- """Save object."""
40
- self.mem[item._jac_.id] = item
41
- if persistent:
42
- # TODO: check if it needs to be saved, i.e. dirty or not
43
- self.save_obj_list[item._jac_.id] = item
44
-
45
- def commit(self) -> None:
46
- """Commit changes to persistent storage, if applicable."""
47
- pass
48
-
49
- def close(self) -> None:
50
- """Close any connection, if applicable."""
51
- self.mem.clear()
52
-
53
-
54
- class ShelveStorage(Memory):
55
- """Shelve storage for jaclang runtime object."""
56
-
57
- storage: shelve.Shelf | None = None
58
-
59
- def __init__(self, session: str = "") -> None:
60
- """Init shelve storage."""
61
- super().__init__()
62
- if session:
63
- self.connect(session)
64
-
65
- def get_obj_from_store(self, obj_id: UUID) -> Architype | None:
66
- """Get object from the underlying store."""
67
- obj = super().get_obj_from_store(obj_id)
68
- if obj is None and self.storage:
69
- obj = self.storage.get(str(obj_id))
70
- if obj is not None:
71
- self.mem[obj_id] = obj
72
-
73
- return obj
74
-
75
- def has_obj_in_store(self, obj_id: UUID | str) -> bool:
76
- """Check if the object exists in the underlying store."""
77
- return obj_id in self.mem or (
78
- str(obj_id) in self.storage if self.storage else False
79
- )
80
-
81
- def commit(self) -> None:
82
- """Commit changes to persistent storage."""
83
- if self.storage is not None:
84
- for obj_id, obj in self.save_obj_list.items():
85
- self.storage[str(obj_id)] = obj
86
- self.save_obj_list.clear()
87
-
88
- def connect(self, session: str) -> None:
89
- """Connect to storage."""
90
- self.session = session
91
- self.storage = shelve.open(session)
92
-
93
- def close(self) -> None:
94
- """Close the storage."""
95
- super().close()
96
- self.commit()
97
- if self.storage:
98
- self.storage.close()
99
- self.storage = None
@@ -1,25 +0,0 @@
1
- import:py from mtllm.llms.base, BaseLLM;
2
-
3
- obj model:BaseLLM: {
4
- can __infer__(meaning_in: str, **kwargs: dict) {
5
- return "The calculated age is 145";
6
- }
7
- }
8
- glob llm = model();
9
- glob theresa: 'mother theresa':list[str, str] = ["Mother Theresa", "1910-08-26"];
10
- obj 'Person'
11
- Person {
12
- has name: 'Name' :str,
13
- dob: 'Date of Birth': str,
14
- age: 'Age': int = None;
15
-
16
- can 'Calculate the Age of a Person'
17
- calculate (cur_year: 'Current Year': int)
18
- -> 'Calculated Age' :int by llm(temperature=0.7, reason=True,incl_info=(self), excl_info=(self.age));
19
- }
20
- with entry{
21
- Einstein = Person(name="Einstein", dob="1879-03-14");
22
- age = Einstein.calculate(cur_year=2024);
23
- Einstein.age = age;
24
- print(Einstein.age);
25
- }
@@ -1,6 +0,0 @@
1
- import:py tkinter as tk ;
2
- import:py from tkinter, messagebox ;
3
-
4
- with entry {
5
- print("package is imported successfully!") ;
6
- }
File without changes
File without changes