ripple-down-rules 0.1.69__tar.gz → 0.2.0__tar.gz

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.
Files changed (33) hide show
  1. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/PKG-INFO +1 -1
  2. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/pyproject.toml +1 -1
  3. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/src/ripple_down_rules/datastructures/callable_expression.py +32 -3
  4. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/src/ripple_down_rules/datastructures/enums.py +1 -1
  5. ripple_down_rules-0.2.0/src/ripple_down_rules/prompt.py +354 -0
  6. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/src/ripple_down_rules/rdr.py +89 -71
  7. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/src/ripple_down_rules/rules.py +38 -33
  8. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/src/ripple_down_rules/utils.py +129 -28
  9. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/src/ripple_down_rules.egg-info/PKG-INFO +1 -1
  10. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/test/test_rdr.py +33 -2
  11. ripple_down_rules-0.1.69/src/ripple_down_rules/prompt.py +0 -161
  12. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/LICENSE +0 -0
  13. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/README.md +0 -0
  14. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/setup.cfg +0 -0
  15. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/src/ripple_down_rules/__init__.py +0 -0
  16. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/src/ripple_down_rules/datasets.py +0 -0
  17. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/src/ripple_down_rules/datastructures/__init__.py +0 -0
  18. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/src/ripple_down_rules/datastructures/case.py +0 -0
  19. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/src/ripple_down_rules/datastructures/dataclasses.py +0 -0
  20. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/src/ripple_down_rules/experts.py +0 -0
  21. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/src/ripple_down_rules/failures.py +0 -0
  22. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/src/ripple_down_rules/helpers.py +0 -0
  23. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/src/ripple_down_rules/rdr_decorators.py +0 -0
  24. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/src/ripple_down_rules.egg-info/SOURCES.txt +0 -0
  25. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/src/ripple_down_rules.egg-info/dependency_links.txt +0 -0
  26. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/src/ripple_down_rules.egg-info/top_level.txt +0 -0
  27. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/test/test_json_serialization.py +0 -0
  28. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/test/test_on_mutagenic.py +0 -0
  29. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/test/test_rdr_alchemy.py +0 -0
  30. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/test/test_rdr_world.py +0 -0
  31. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/test/test_relational_rdr.py +0 -0
  32. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/test/test_relational_rdr_alchemy.py +0 -0
  33. {ripple_down_rules-0.1.69 → ripple_down_rules-0.2.0}/test/test_sql_model.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ripple_down_rules
3
- Version: 0.1.69
3
+ Version: 0.2.0
4
4
  Summary: Implements the various versions of Ripple Down Rules (RDR) for knowledge representation and reasoning.
5
5
  Author-email: Abdelrhman Bassiouny <abassiou@uni-bremen.de>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
6
6
 
7
7
  [project]
8
8
  name = "ripple_down_rules"
9
- version = "0.1.69"
9
+ version = "0.2.0"
10
10
  description = "Implements the various versions of Ripple Down Rules (RDR) for knowledge representation and reasoning."
11
11
  readme = "README.md"
12
12
  authors = [{ name = "Abdelrhman Bassiouny", email = "abassiou@uni-bremen.de" }]
@@ -9,7 +9,7 @@ from typing_extensions import Type, Optional, Any, List, Union, Tuple, Dict, Set
9
9
 
10
10
  from .case import create_case, Case
11
11
  from ..utils import SubclassJSONSerializer, get_full_class_name, get_type_from_string, conclusion_to_json, is_iterable, \
12
- build_user_input_from_conclusion, encapsulate_user_input
12
+ build_user_input_from_conclusion, encapsulate_user_input, extract_function_source
13
13
 
14
14
 
15
15
  class VariableVisitor(ast.NodeVisitor):
@@ -109,7 +109,7 @@ class CallableExpression(SubclassJSONSerializer):
109
109
  if user_input is None:
110
110
  user_input = build_user_input_from_conclusion(conclusion)
111
111
  self.conclusion: Optional[Any] = conclusion
112
- self.user_input: str = encapsulate_user_input(user_input, self.encapsulating_function)
112
+ self._user_input: str = encapsulate_user_input(user_input, self.encapsulating_function)
113
113
  if conclusion_type is not None:
114
114
  if is_iterable(conclusion_type):
115
115
  conclusion_type = tuple(conclusion_type)
@@ -156,6 +156,35 @@ class CallableExpression(SubclassJSONSerializer):
156
156
  f"return _cond1(case) and _cond2(case)")
157
157
  return CallableExpression(new_user_input, conclusion_type=self.conclusion_type)
158
158
 
159
+ def update_user_input_from_file(self, file_path: str, function_name: str):
160
+ """
161
+ Update the user input from a file.
162
+ """
163
+ new_function_body = extract_function_source(file_path, [function_name])[function_name]
164
+ if new_function_body is None:
165
+ return
166
+ self.user_input = self.encapsulating_function + '\n' + new_function_body
167
+
168
+ @property
169
+ def user_input(self):
170
+ """
171
+ Get the user input.
172
+ """
173
+ return self._user_input
174
+
175
+ @user_input.setter
176
+ def user_input(self, value: str):
177
+ """
178
+ Set the user input.
179
+ """
180
+ if value is not None:
181
+ self._user_input = encapsulate_user_input(value, self.encapsulating_function)
182
+ self.scope = get_used_scope(self.user_input, self.scope)
183
+ self.expression_tree = parse_string_to_expression(self.user_input)
184
+ self.code = compile_expression_to_code(self.expression_tree)
185
+ self.visitor = VariableVisitor()
186
+ self.visitor.visit(self.expression_tree)
187
+
159
188
  def __eq__(self, other):
160
189
  """
161
190
  Check if two callable expressions are equal.
@@ -225,7 +254,7 @@ def parse_string_to_expression(expression_str: str) -> AST:
225
254
  :param expression_str: The string which will be parsed.
226
255
  :return: The parsed expression.
227
256
  """
228
- if not expression_str.startswith('def'):
257
+ if not expression_str.startswith(CallableExpression.encapsulating_function):
229
258
  expression_str = encapsulate_user_input(expression_str, CallableExpression.encapsulating_function)
230
259
  mode = 'exec' if expression_str.startswith('def') else 'eval'
231
260
  tree = ast.parse(expression_str, mode=mode)
@@ -59,7 +59,7 @@ class PromptFor(Enum):
59
59
  """
60
60
  Prompt for rule conditions about a case.
61
61
  """
62
- Conclusion: str = "conclusion"
62
+ Conclusion: str = "value"
63
63
  """
64
64
  Prompt for rule conclusion about a case.
65
65
  """
@@ -0,0 +1,354 @@
1
+ import ast
2
+ import logging
3
+ import os
4
+ import subprocess
5
+ import tempfile
6
+ from _ast import AST
7
+ from functools import cached_property
8
+ from textwrap import indent, dedent
9
+
10
+ from IPython.core.magic import register_line_magic, line_magic, Magics, magics_class
11
+ from IPython.terminal.embed import InteractiveShellEmbed
12
+ from traitlets.config import Config
13
+ from typing_extensions import List, Optional, Tuple, Dict, Type, Union
14
+
15
+ from .datastructures.enums import PromptFor
16
+ from .datastructures.case import Case
17
+ from .datastructures.callable_expression import CallableExpression, parse_string_to_expression
18
+ from .datastructures.dataclasses import CaseQuery
19
+ from .utils import extract_dependencies, contains_return_statement, make_set, get_imports_from_scope, make_list, \
20
+ get_import_from_type, get_imports_from_types, is_iterable, extract_function_source, encapsulate_user_input
21
+
22
+
23
+ @magics_class
24
+ class MyMagics(Magics):
25
+ def __init__(self, shell, scope, output_type: Optional[Type] = None, func_name: str = "user_case",
26
+ func_doc: str = "User defined function to be executed on the case.",
27
+ code_to_modify: Optional[str] = None):
28
+ super().__init__(shell)
29
+ self.scope = scope
30
+ self.temp_file_path = None
31
+ self.func_name = func_name
32
+ self.func_doc = func_doc
33
+ self.code_to_modify = code_to_modify
34
+ self.output_type = make_list(output_type) if output_type is not None else None
35
+ self.user_edit_line = 0
36
+ self.function_signature: Optional[str] = None
37
+ self.build_function_signature()
38
+
39
+ @line_magic
40
+ def edit_case(self, line):
41
+
42
+ boilerplate_code = self.build_boilerplate_code()
43
+
44
+ self.write_to_file(boilerplate_code)
45
+
46
+ print(f"Opening {self.temp_file_path} in PyCharm...")
47
+ subprocess.Popen(["pycharm", "--line", str(self.user_edit_line), self.temp_file_path])
48
+
49
+ def build_boilerplate_code(self):
50
+ imports = self.get_imports()
51
+ self.build_function_signature()
52
+ if self.code_to_modify is not None:
53
+ body = indent(dedent(self.code_to_modify), ' ')
54
+ else:
55
+ body = " # Write your code here\n pass"
56
+ boilerplate = f"""{imports}\n\n{self.function_signature}\n \"\"\"{self.func_doc}\"\"\"\n{body}"""
57
+ self.user_edit_line = imports.count('\n')+6
58
+ return boilerplate
59
+
60
+ def build_function_signature(self):
61
+ if self.output_type is None:
62
+ output_type_hint = ""
63
+ elif len(self.output_type) == 1:
64
+ output_type_hint = f" -> {self.output_type[0].__name__}"
65
+ else:
66
+ output_type_hint = f" -> Union[{', '.join([t.__name__ for t in self.output_type])}]"
67
+ self.function_signature = f"def {self.func_name}(case: {self.case_type.__name__}){output_type_hint}:"
68
+
69
+ def write_to_file(self, code: str):
70
+ tmp = tempfile.NamedTemporaryFile(mode='w+', delete=False, suffix=".py",
71
+ dir=os.path.dirname(self.scope['__file__']))
72
+ tmp.write(code)
73
+ tmp.flush()
74
+ self.temp_file_path = tmp.name
75
+ tmp.close()
76
+
77
+ def get_imports(self):
78
+ case_type_import = f"from {self.case_type.__module__} import {self.case_type.__name__}"
79
+ if self.output_type is None:
80
+ output_type_imports = [f"from typing_extensions import Any"]
81
+ else:
82
+ output_type_imports = get_imports_from_types(self.output_type)
83
+ if len(self.output_type) > 1:
84
+ output_type_imports.append("from typing_extensions import Union")
85
+ print(output_type_imports)
86
+ imports = get_imports_from_scope(self.scope)
87
+ imports = [i for i in imports if ("get_ipython" not in i)]
88
+ if case_type_import not in imports:
89
+ imports.append(case_type_import)
90
+ imports.extend([oti for oti in output_type_imports if oti not in imports])
91
+ imports = set(imports)
92
+ return '\n'.join(imports)
93
+
94
+ @cached_property
95
+ def case_type(self) -> Type:
96
+ """
97
+ Get the type of the case object in the current scope.
98
+
99
+ :return: The type of the case object.
100
+ """
101
+ case = self.scope['case']
102
+ return case._obj_type if isinstance(case, Case) else type(case)
103
+
104
+ @line_magic
105
+ def load_case(self, line):
106
+ if not self.temp_file_path:
107
+ print("No file to load. Run %edit_case first.")
108
+ return
109
+
110
+ with open(self.temp_file_path, 'r') as f:
111
+ source = f.read()
112
+
113
+ tree = ast.parse(source)
114
+ for node in tree.body:
115
+ if isinstance(node, ast.FunctionDef) and node.name == self.func_name:
116
+ exec_globals = {}
117
+ exec(source, self.scope, exec_globals)
118
+ user_function = exec_globals[self.func_name]
119
+ self.shell.user_ns[self.func_name] = user_function
120
+ print(f"Loaded `{self.func_name}` function into user namespace.")
121
+ return
122
+
123
+ print(f"Function `{self.func_name}` not found.")
124
+
125
+
126
+ class CustomInteractiveShell(InteractiveShellEmbed):
127
+ def __init__(self, output_type: Union[Type, Tuple[Type], None] = None, func_name: Optional[str] = None,
128
+ func_doc: Optional[str] = None, code_to_modify: Optional[str] = None, **kwargs):
129
+ super().__init__(**kwargs)
130
+ keys = ['output_type', 'func_name', 'func_doc', 'code_to_modify']
131
+ values = [output_type, func_name, func_doc, code_to_modify]
132
+ magics_kwargs = {key: value for key, value in zip(keys, values) if value is not None}
133
+ self.my_magics = MyMagics(self, self.user_ns, **magics_kwargs)
134
+ self.register_magics(self.my_magics)
135
+ self.all_lines = []
136
+
137
+ def run_cell(self, raw_cell: str, **kwargs):
138
+ """
139
+ Override the run_cell method to capture return statements.
140
+ """
141
+ if contains_return_statement(raw_cell) and 'def ' not in raw_cell:
142
+ if self.my_magics.func_name in raw_cell:
143
+ self.all_lines = extract_function_source(self.my_magics.temp_file_path,
144
+ self.my_magics.func_name,
145
+ join_lines=False)[self.my_magics.func_name]
146
+ self.all_lines.append(raw_cell)
147
+ print("Exiting shell on `return` statement.")
148
+ self.history_manager.store_inputs(line_num=self.execution_count, source=raw_cell)
149
+ self.ask_exit()
150
+ return None
151
+ result = super().run_cell(raw_cell, **kwargs)
152
+ if result.error_in_exec is None and result.error_before_exec is None:
153
+ self.all_lines.append(raw_cell)
154
+ return result
155
+
156
+
157
+ class IPythonShell:
158
+ """
159
+ Create an embedded Ipython shell that can be used to prompt the user for input.
160
+ """
161
+
162
+ def __init__(self, scope: Optional[Dict] = None, header: Optional[str] = None,
163
+ output_type: Optional[Type] = None, prompt_for: Optional[PromptFor] = None,
164
+ attribute_name: Optional[str] = None, attribute_type: Optional[Type] = None,
165
+ code_to_modify: Optional[str] = None):
166
+ """
167
+ Initialize the Ipython shell with the given scope and header.
168
+
169
+ :param scope: The scope to use for the shell.
170
+ :param header: The header to display when the shell is started.
171
+ :param output_type: The type of the output from user input.
172
+ :param prompt_for: The type of information to ask the user about.
173
+ :param attribute_name: The name of the attribute of the case.
174
+ :param attribute_type: The type of the attribute of the case.
175
+ :param code_to_modify: The code to modify. If given, will be used as a start for user to modify.
176
+ """
177
+ self.scope: Dict = scope or {}
178
+ self.header: str = header or ">>> Embedded Ipython Shell"
179
+ self.output_type: Optional[Type] = output_type
180
+ self.prompt_for: Optional[PromptFor] = prompt_for
181
+ self.attribute_name: Optional[str] = attribute_name
182
+ self.attribute_type: Optional[Type] = attribute_type
183
+ self.code_to_modify: Optional[str] = code_to_modify
184
+ self.user_input: Optional[str] = None
185
+ self.func_name: str = ""
186
+ self.func_doc: str = ""
187
+ self.shell: CustomInteractiveShell = self._init_shell()
188
+ self.all_code_lines: List[str] = []
189
+
190
+ def _init_shell(self):
191
+ """
192
+ Initialize the Ipython shell with a custom configuration.
193
+ """
194
+ cfg = Config()
195
+ self.build_func_name_and_doc()
196
+ shell = CustomInteractiveShell(config=cfg, user_ns=self.scope, banner1=self.header,
197
+ output_type=self.output_type, func_name=self.func_name, func_doc=self.func_doc,
198
+ code_to_modify=self.code_to_modify)
199
+ return shell
200
+
201
+ def build_func_name_and_doc(self) -> Tuple[str, str]:
202
+ """
203
+ Build the function name and docstring for the user-defined function.
204
+
205
+ :return: A tuple containing the function name and docstring.
206
+ """
207
+ case = self.scope['case']
208
+ case_type = case._obj_type if isinstance(case, Case) else type(case)
209
+ self.func_name = self.build_func_name(case_type)
210
+ self.func_doc = self.build_func_doc(case_type)
211
+
212
+ def build_func_doc(self, case_type: Type):
213
+ if self.prompt_for == PromptFor.Conditions:
214
+ func_doc = (f"Get conditions on whether it's possible to conclude a value"
215
+ f" for {case_type.__name__}.{self.attribute_name}")
216
+ else:
217
+ func_doc = f"Get possible value(s) for {case_type.__name__}.{self.attribute_name}"
218
+ if is_iterable(self.attribute_type):
219
+ possible_types = [t.__name__ for t in self.attribute_type if t not in [list, set]]
220
+ func_doc += f" of types list/set of {' and/or '.join(possible_types)}"
221
+ else:
222
+ func_doc += f" of type {self.attribute_type.__name__}"
223
+ return func_doc
224
+
225
+ def build_func_name(self, case_type: Type):
226
+ func_name = f"get_{self.prompt_for.value.lower()}_for"
227
+ func_name += f"_{case_type.__name__}"
228
+ if self.attribute_name is not None:
229
+ func_name += f"_{self.attribute_name}"
230
+ if is_iterable(self.attribute_type):
231
+ output_names = [f"{t.__name__}" for t in self.attribute_type if t not in [list, set]]
232
+ else:
233
+ output_names = [self.attribute_type.__name__] if self.attribute_type is not None else None
234
+ if output_names is not None:
235
+ func_name += '_of_type_' + '_'.join(output_names)
236
+ return func_name.lower()
237
+
238
+ def run(self):
239
+ """
240
+ Run the embedded shell.
241
+ """
242
+ while True:
243
+ try:
244
+ self.shell()
245
+ self.update_user_input_from_code_lines()
246
+ break
247
+ except Exception as e:
248
+ logging.error(e)
249
+ print(e)
250
+
251
+ def update_user_input_from_code_lines(self):
252
+ """
253
+ Update the user input from the code lines captured in the shell.
254
+ """
255
+ if len(self.shell.all_lines) == 1 and self.shell.all_lines[0].replace('return', '').strip() == '':
256
+ self.user_input = None
257
+ else:
258
+ self.all_code_lines = extract_dependencies(self.shell.all_lines)
259
+ if len(self.all_code_lines) == 1 and self.all_code_lines[0].strip() == '':
260
+ self.user_input = None
261
+ else:
262
+ import pdb; pdb.set_trace()
263
+ self.user_input = '\n'.join(self.all_code_lines)
264
+ self.user_input = encapsulate_user_input(self.user_input, self.shell.my_magics.function_signature,
265
+ self.func_doc)
266
+ if f"return {self.func_name}(case)" not in self.user_input:
267
+ self.user_input = self.user_input.strip() + f"\nreturn {self.func_name}(case)"
268
+
269
+
270
+ def prompt_user_for_expression(case_query: CaseQuery, prompt_for: PromptFor, prompt_str: Optional[str] = None)\
271
+ -> Tuple[Optional[str], Optional[CallableExpression]]:
272
+ """
273
+ Prompt the user for an executable python expression to the given case query.
274
+
275
+ :param case_query: The case query to prompt the user for.
276
+ :param prompt_for: The type of information ask user about.
277
+ :param prompt_str: The prompt string to display to the user.
278
+ :return: A callable expression that takes a case and executes user expression on it.
279
+ """
280
+ prev_user_input: Optional[str] = None
281
+ while True:
282
+ user_input, expression_tree = prompt_user_about_case(case_query, prompt_for, prompt_str,
283
+ code_to_modify=prev_user_input)
284
+ prev_user_input = '\n'.join(user_input.split('\n')[2:-1])
285
+ if user_input is None:
286
+ if prompt_for == PromptFor.Conclusion:
287
+ print("No conclusion provided. Exiting.")
288
+ return None, None
289
+ else:
290
+ print("Conditions must be provided. Please try again.")
291
+ continue
292
+ conclusion_type = bool if prompt_for == PromptFor.Conditions else case_query.attribute_type
293
+ callable_expression = CallableExpression(user_input, conclusion_type, expression_tree=expression_tree,
294
+ scope=case_query.scope)
295
+ try:
296
+ result = callable_expression(case_query.case)
297
+ result = make_list(result)
298
+ if len(result) == 0:
299
+ print(f"The given expression gave an empty result for case {case_query.name}, please modify")
300
+ continue
301
+ break
302
+ except Exception as e:
303
+ logging.error(e)
304
+ print(e)
305
+ return user_input, callable_expression
306
+
307
+
308
+ def prompt_user_about_case(case_query: CaseQuery, prompt_for: PromptFor,
309
+ prompt_str: Optional[str] = None,
310
+ code_to_modify: Optional[str] = None) -> Tuple[Optional[str], Optional[AST]]:
311
+ """
312
+ Prompt the user for input.
313
+
314
+ :param case_query: The case query to prompt the user for.
315
+ :param prompt_for: The type of information the user should provide for the given case.
316
+ :param prompt_str: The prompt string to display to the user.
317
+ :param code_to_modify: The code to modify. If given will be used as a start for user to modify.
318
+ :return: The user input, and the executable expression that was parsed from the user input.
319
+ """
320
+ if prompt_str is None:
321
+ prompt_str = f"Give {prompt_for} for {case_query.name}"
322
+ scope = {'case': case_query.case, **case_query.scope}
323
+ output_type = case_query.attribute_type if prompt_for == PromptFor.Conclusion else bool
324
+ shell = IPythonShell(scope=scope, header=prompt_str, output_type=output_type, prompt_for=prompt_for,
325
+ attribute_name=case_query.attribute_name, attribute_type=case_query.attribute_type,
326
+ code_to_modify=code_to_modify)
327
+ return prompt_user_input_and_parse_to_expression(shell=shell)
328
+
329
+
330
+ def prompt_user_input_and_parse_to_expression(shell: Optional[IPythonShell] = None,
331
+ user_input: Optional[str] = None)\
332
+ -> Tuple[Optional[str], Optional[ast.AST]]:
333
+ """
334
+ Prompt the user for input.
335
+
336
+ :param shell: The Ipython shell to use for prompting the user.
337
+ :param user_input: The user input to use. If given, the user input will be used instead of prompting the user.
338
+ :return: The user input and the AST tree.
339
+ """
340
+ while True:
341
+ if user_input is None:
342
+ shell = IPythonShell() if shell is None else shell
343
+ shell.run()
344
+ user_input = shell.user_input
345
+ if user_input is None:
346
+ return None, None
347
+ print(user_input)
348
+ try:
349
+ return user_input, parse_string_to_expression(user_input)
350
+ except Exception as e:
351
+ msg = f"Error parsing expression: {e}"
352
+ logging.error(msg)
353
+ print(msg)
354
+ user_input = None