diff --git a/clorm/_clingo.py b/clorm/_clingo.py index 108a94b..c9ade42 100644 --- a/clorm/_clingo.py +++ b/clorm/_clingo.py @@ -69,6 +69,7 @@ def _check_is_func(obj: Any, name: str) -> None: # Wrap clingo.Model and override some functions # ------------------------------------------------------------------------------ + # class Model(OModel, metaclass=WrapperMetaClass): class ModelOverride(object): """Provides access to a model during a solve call. @@ -236,6 +237,7 @@ class ClormSolveHandle(SolveHandleOverride, OSolveHandle): # Wrap clingo.Control and override some functions # ------------------------------------------------------------------------------ + # ------------------------------------------------------------------------------ # Helper functions to expand the assumptions list as part of a solve() call. The # assumptions list is a list of argument-boolean pairs where the argument can be @@ -255,7 +257,7 @@ def _add_fact(fact: Union[Predicate, Symbol], bval: bool) -> None: clingo_assump.append((raw, bool(bval))) try: - for (arg, bval) in assumptions: + for arg, bval in assumptions: if isinstance(arg, Predicate): _add_fact(arg, bval) elif isinstance(arg, Iterable): diff --git a/clorm/orm/core.py b/clorm/orm/core.py index fe9285b..7faada4 100644 --- a/clorm/orm/core.py +++ b/clorm/orm/core.py @@ -293,6 +293,7 @@ def __hash__(self): # conditions and other boolean conditions. # ------------------------------------------------------------------------------ + # comparator functions that always return true (or false). This is useful for # the cross product join operator that always returns true def trueall(x, y): @@ -1205,6 +1206,7 @@ def kwargs_check_keys(validkeys, inputkeys): # a field") between python and clingo. # ------------------------------------------------------------------------------ + # Create the pytocl and cltopy class member functions. If their inherit directly # from BaseField then just return the result of the function. If they inherit # from a sub-class of BaseField then call the parents conversion function first. @@ -1290,6 +1292,7 @@ def _raise_pytocl_nie(v): # and unifies, and the properties: default and has_default # ------------------------------------------------------------------------------ + # Mixin class to be able to use both MetaClasses class _AbstractBaseFieldMeta(abc.ABCMeta, _BaseFieldMeta): pass @@ -1817,6 +1820,7 @@ def _process_field_definition(field_defn: _FieldDefinition) -> Type[BaseField]: # restricts the allowable values. # ------------------------------------------------------------------------------ + # Support for refine_field def _refine_field_functor(subclass_name, field_class, valfunc): def _test_value(v): @@ -2563,11 +2567,11 @@ def _magic_name(name): PathIdentity = collections.namedtuple("PathIdentity", "predicate name") + # -------------------------------------------------------------------------- # One PredicateDefn object for each Predicate sub-class # -------------------------------------------------------------------------- class PredicateDefn(object): - """Encapsulates some meta-data for a Predicate definition. Each Predicate class will have a corresponding PredicateDefn object that specifies some @@ -2828,6 +2832,7 @@ def _set_fn(fname: str, docstring: str): # Metaclass constructor support functions to create the fields # ------------------------------------------------------------------------------ + # Generate a default predicate name from the Predicate class name. def _predicatedefn_default_predicate_name(class_name): @@ -3266,6 +3271,7 @@ def __iter__(self) -> Iterator[PredicatePath]: # underlying Symbol object. # ------------------------------------------------------------------------------ + # Mixin class to be able to use both MetaClasses class _AbstractPredicateMeta(abc.ABCMeta, _PredicateMeta): pass @@ -3546,6 +3552,7 @@ def simple_predicate( # Internal supporting functions # ------------------------------------------------------------------------------ + # ------------------------------------------------------------------------------ # Helper function to check if all the paths in a collection are root paths and # return path objects. diff --git a/clorm/orm/noclingo.py b/clorm/orm/noclingo.py index 87aba20..667fcd9 100644 --- a/clorm/orm/noclingo.py +++ b/clorm/orm/noclingo.py @@ -47,6 +47,7 @@ will raise an exception. """ + # -------------------------------------------------------------------------------- # -------------------------------------------------------------------------------- diff --git a/clorm/orm/query.py b/clorm/orm/query.py index 2c2a030..97471c9 100644 --- a/clorm/orm/query.py +++ b/clorm/orm/query.py @@ -57,12 +57,12 @@ # Defining and manipulating conditional elements # ------------------------------------------------------------------------------ + # ------------------------------------------------------------------------------ # Placeholder allows for variable substituion of a query. Placeholder is # an abstract class that exposes no API other than its existence. # ------------------------------------------------------------------------------ class Placeholder(abc.ABC): - r"""An abstract class for defining parameterised queries. Currently, Clorm supports 4 placeholders: ph1\_, ph2\_, ph3\_, ph4\_. These @@ -514,6 +514,7 @@ def membership_op_keyable(sc, indexes): # is not exposed outside clorm. # ------------------------------------------------------------------------------ + # Helper function to try to convert Python tuples into a matching clorm anon tuple. With this # we can pass a Python tuple to a query and not have to overload the Predicate comparison # operator and hash function to match the tuple. @@ -2233,6 +2234,7 @@ def num(sc): # describes the plan to execute a single link in a join. # ------------------------------------------------------------------------------ + # Check that the formula only refers to paths with the allowable roots def _check_roots(allowable_roots, formula): if not formula: @@ -3067,6 +3069,7 @@ def make_query_plan(indexed_paths, qspec): # generating an actual query. # ------------------------------------------------------------------------------ + # ------------------------------------------------------------------------------ # Creates a mechanism for sorting using the order_by statements within queries. # diff --git a/clorm/orm/templating.py b/clorm/orm/templating.py index 1fd7f6f..2400f89 100644 --- a/clorm/orm/templating.py +++ b/clorm/orm/templating.py @@ -21,6 +21,7 @@ def expand_template(template: str, **kwargs: str) -> str: line to preserve the correct indentation. """ + # Add spaces to each line of some multi-text input def add_spaces(num, text): space = " " * num diff --git a/tests/support.py b/tests/support.py index be7888c..66e81f2 100644 --- a/tests/support.py +++ b/tests/support.py @@ -4,6 +4,7 @@ # Support functions for the unit tests # ------------------------------------------------------------------------------ + # ------------------------------------------------------------------------------ # Helper function for helping to test for good error messages. # ------------------------------------------------------------------------------ diff --git a/tests/test_orm_atsyntax.py b/tests/test_orm_atsyntax.py index b23a968..203db82 100644 --- a/tests/test_orm_atsyntax.py +++ b/tests/test_orm_atsyntax.py @@ -426,6 +426,7 @@ def test_register(self): SF = StringField IF = IntegerField CF = ConstantField + # Functions to add to the context def add(a: IF, b: IF) -> IF: return a + b diff --git a/tests/test_orm_factbase.py b/tests/test_orm_factbase.py index ce24228..a94ecc6 100644 --- a/tests/test_orm_factbase.py +++ b/tests/test_orm_factbase.py @@ -589,16 +589,25 @@ class Meta: # Test the asp output string with the sorted flag # -------------------------------------------------------------------------- def test_factbase_aspstr_sorted(self): - class A(Predicate, name="bb"): + class A(Predicate): a = IntegerField - class B(Predicate, name="aa"): + class Meta: + name = "bb" + + class B(Predicate): a = IntegerField - class C(Predicate, name="aa"): + class Meta: + name = "aa" + + class C(Predicate): a = IntegerField b = IntegerField + class Meta: + name = "aa" + def tostr(facts): return ".\n".join([str(f) for f in facts]) diff --git a/tests/test_orm_symbols_facts.py b/tests/test_orm_symbols_facts.py index d121e89..6fca429 100644 --- a/tests/test_orm_symbols_facts.py +++ b/tests/test_orm_symbols_facts.py @@ -126,6 +126,7 @@ class Fun(ComplexTerm): anum = IntegerField() afun = Fun.Field() + # afun=ComplexField(Fun) class Meta: name = "afact"