Not initialiazed variables now returns BuiltinConcepts.NOT_INITIALIZED
This commit is contained in:
@@ -61,6 +61,7 @@ class BuiltinConcepts(Enum):
|
||||
EXPLANATION = "explanation"
|
||||
PRECEDENCE = "precedence" # use to set priority among concepts when parsing
|
||||
ASSOCIATIVITY = "associativity" # use to set priority among concepts when parsing
|
||||
NOT_INITIALIZED = "not initialized"
|
||||
|
||||
NODE = "node"
|
||||
GENERIC_NODE = "generic node"
|
||||
@@ -104,7 +105,8 @@ BuiltinErrors = [str(e) for e in {
|
||||
BuiltinConcepts.CONCEPT_ALREADY_IN_SET,
|
||||
BuiltinConcepts.NOT_A_SET,
|
||||
BuiltinConcepts.WHERE_CLAUSE_FAILED,
|
||||
BuiltinConcepts.CHICKEN_AND_EGG
|
||||
BuiltinConcepts.CHICKEN_AND_EGG,
|
||||
BuiltinConcepts.NOT_INITIALIZED
|
||||
}]
|
||||
|
||||
"""
|
||||
|
||||
+2
-1
@@ -391,7 +391,8 @@ class Concept:
|
||||
:return:
|
||||
"""
|
||||
if prop_name not in self.values:
|
||||
return None
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
return BuiltinConcepts.NOT_INITIALIZED
|
||||
return self.values[prop_name].value
|
||||
|
||||
def variables(self):
|
||||
|
||||
@@ -657,7 +657,7 @@ class Sheerka(Concept):
|
||||
if not isinstance(obj, Concept):
|
||||
return obj
|
||||
|
||||
if obj.body is None:
|
||||
if obj.body is BuiltinConcepts.NOT_INITIALIZED:
|
||||
return obj
|
||||
|
||||
if reduce_simple_list and (isinstance(obj.body, list) or isinstance(obj.body, set)) and len(obj.body) == 1:
|
||||
|
||||
@@ -21,7 +21,7 @@ class EvalEvaluator(AllReturnValuesEvaluator):
|
||||
result = []
|
||||
|
||||
for ret_val in return_values:
|
||||
if ret_val.status and isinstance(ret_val.body, Concept) and ret_val.body.body:
|
||||
if ret_val.status and isinstance(ret_val.body, Concept) and ret_val.body.body != BuiltinConcepts.NOT_INITIALIZED:
|
||||
context.log(f"Evaluating {ret_val.body}", who=self)
|
||||
result.append(sheerka.ret(self.name, True, ret_val.body.body, parents=[ret_val]))
|
||||
elif ret_val.status and sheerka.isaset(context, ret_val.body):
|
||||
|
||||
@@ -88,7 +88,7 @@ class SheerkaPrinter:
|
||||
|
||||
if instructions.recursive_props:
|
||||
for k, v in instructions.recursive_props.items():
|
||||
if hasattr(item, k) and v > 0 and (value := getattr(item, k)) is not None:
|
||||
if hasattr(item, k) and v > 0 and (value := getattr(item, k)) != BuiltinConcepts.NOT_INITIALIZED:
|
||||
self.fp(instructions.recurse(k), value)
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -9,7 +9,7 @@ from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
||||
class TestSheerkaEvaluateConcept(TestUsingMemoryBasedSheerka):
|
||||
|
||||
@pytest.mark.parametrize("body, expected", [
|
||||
(None, None),
|
||||
(None, BuiltinConcepts.NOT_INITIALIZED),
|
||||
("", ""),
|
||||
("1", 1),
|
||||
("1+1", 2),
|
||||
@@ -132,7 +132,7 @@ class TestSheerkaEvaluateConcept(TestUsingMemoryBasedSheerka):
|
||||
|
||||
evaluated = sheerka.evaluate_concept(context, concept)
|
||||
|
||||
assert evaluated == CB("foo", CB("a", None))
|
||||
assert evaluated == CB("foo", CB("a", BuiltinConcepts.NOT_INITIALIZED))
|
||||
assert evaluated.metadata.is_evaluated
|
||||
assert evaluated.body.metadata.is_evaluated
|
||||
|
||||
@@ -176,9 +176,9 @@ class TestSheerkaEvaluateConcept(TestUsingMemoryBasedSheerka):
|
||||
evaluated = sheerka.evaluate_concept(context, concept_d)
|
||||
|
||||
assert evaluated.key == concept_d.key
|
||||
expected = CB("c", CB("b", CB("a", None)))
|
||||
expected = CB("c", CB("b", CB("a", BuiltinConcepts.NOT_INITIALIZED)))
|
||||
assert evaluated.body == expected
|
||||
assert sheerka.objvalue(evaluated) == CB("a", None)
|
||||
assert sheerka.objvalue(evaluated) == CB("a", BuiltinConcepts.NOT_INITIALIZED)
|
||||
assert evaluated.metadata.is_evaluated
|
||||
|
||||
def test_i_can_evaluate_concept_when_variables_reference_others_concepts(self):
|
||||
|
||||
@@ -186,11 +186,11 @@ class TestSheerkaUsingMemoryBasedSheerka(TestUsingMemoryBasedSheerka):
|
||||
|
||||
new = sheerka.new(template.key)
|
||||
assert not new.metadata.is_evaluated
|
||||
assert not new.body
|
||||
assert new.body == BuiltinConcepts.NOT_INITIALIZED
|
||||
|
||||
new = sheerka.new((None, template.id))
|
||||
assert not new.metadata.is_evaluated
|
||||
assert not new.body
|
||||
assert new.body == BuiltinConcepts.NOT_INITIALIZED
|
||||
|
||||
def test_i_cannot_instantiate_an_unknown_concept(self):
|
||||
sheerka = self.get_sheerka()
|
||||
|
||||
@@ -64,7 +64,7 @@ class TestSheerkaNonRegMemory(TestUsingMemoryBasedSheerka):
|
||||
|
||||
# sanity check
|
||||
evaluated = sheerka.evaluate_concept(self.get_context(eval_body=True), return_value)
|
||||
assert evaluated == simplec("un", simplec("one", None))
|
||||
assert evaluated == simplec("un", simplec("one", BuiltinConcepts.NOT_INITIALIZED))
|
||||
|
||||
def test_i_can_recognize_concept_with_no_body(self):
|
||||
sheerka = self.get_sheerka()
|
||||
@@ -734,7 +734,7 @@ as:
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert sheerka.isinstance(res[0].body, "foobar")
|
||||
assert res[0].body.body is None
|
||||
assert res[0].body.body == BuiltinConcepts.NOT_INITIALIZED
|
||||
|
||||
res = sheerka.evaluate_user_input("eval foo bar")
|
||||
assert len(res) == 1
|
||||
|
||||
@@ -447,11 +447,11 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
# explicit validations of the compiled
|
||||
concept_foo = sequences[0][0].concept
|
||||
assert concept_foo.body is None
|
||||
assert concept_foo.body == BuiltinConcepts.NOT_INITIALIZED
|
||||
assert concept_foo.compiled == {ConceptParts.BODY: DoNotResolve("one two")}
|
||||
|
||||
concept_bar = sequences[1][0].concept
|
||||
assert concept_bar.body is None
|
||||
assert concept_bar.body == BuiltinConcepts.NOT_INITIALIZED
|
||||
assert concept_bar.compiled == {
|
||||
ConceptParts.BODY: concept_foo,
|
||||
"foo": concept_foo
|
||||
@@ -473,11 +473,11 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
# explicit validations of the compiled
|
||||
concept_foo = sequences[0][0].concept
|
||||
assert concept_foo.body is None
|
||||
assert concept_foo.body == BuiltinConcepts.NOT_INITIALIZED
|
||||
assert len(concept_foo.compiled) == 0 # because there is a body defined in the metadata
|
||||
|
||||
concept_bar = sequences[1][0].concept
|
||||
assert concept_bar.body is None
|
||||
assert concept_bar.body == BuiltinConcepts.NOT_INITIALIZED
|
||||
assert concept_bar.compiled == {
|
||||
ConceptParts.BODY: concept_foo,
|
||||
"foo": concept_foo
|
||||
@@ -500,18 +500,18 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
# explicit validations of the compiled
|
||||
concept_foo = sequences[0][0].concept
|
||||
assert concept_foo.body is None
|
||||
assert concept_foo.body == BuiltinConcepts.NOT_INITIALIZED
|
||||
assert concept_foo.compiled == {ConceptParts.BODY: DoNotResolve("one two")}
|
||||
|
||||
concept_bar = sequences[1][0].concept
|
||||
assert concept_bar.body is None
|
||||
assert concept_bar.body == BuiltinConcepts.NOT_INITIALIZED
|
||||
assert concept_bar.compiled == {
|
||||
ConceptParts.BODY: concept_foo,
|
||||
"foo": concept_foo
|
||||
}
|
||||
|
||||
concept_baz = sequences[2][0].concept
|
||||
assert concept_baz.body is None
|
||||
assert concept_baz.body == BuiltinConcepts.NOT_INITIALIZED
|
||||
assert concept_baz.compiled == {
|
||||
ConceptParts.BODY: concept_bar,
|
||||
"bar": concept_bar,
|
||||
@@ -631,7 +631,7 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
# explicit validations of the compiled
|
||||
concept_foo = sequences[0].concept
|
||||
assert concept_foo.body is None
|
||||
assert concept_foo.body == BuiltinConcepts.NOT_INITIALIZED
|
||||
assert concept_foo.compiled == {'number': my_map["number"],
|
||||
'two': my_map["two"],
|
||||
ConceptParts.BODY: DoNotResolve(value='twenty two')}
|
||||
@@ -642,7 +642,7 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
# explicit validations of the compiled
|
||||
concept_foo = sequences[0].concept
|
||||
assert concept_foo.body is None
|
||||
assert concept_foo.body == BuiltinConcepts.NOT_INITIALIZED
|
||||
assert concept_foo.compiled == {'number': my_map["number"],
|
||||
'one': my_map["one"],
|
||||
ConceptParts.BODY: DoNotResolve(value='twenty one')}
|
||||
|
||||
Reference in New Issue
Block a user