def __add__(self, other):
return CnfList(super().__add__(other))
+ def add(self, *args, **kwargs):
+ """
+ Add a CNF variable to the list.
+
+ Arguments can either be a single instance of the :py:class:`Cnf`
+ class or a list of arguments to be passed to the constructor of
+ that class. Similar to the :py:func:`add_child` method for a `Cnf`.
+
+ :returns: the instance that was created
+ :rtype: :py:class:`Cnf`
+ """
+ # support passing a Cnf instance
+ if len(args) == 1 and not kwargs:
+ cnf = args[0]
+ assert isinstance(cnf, Cnf), "A Cnf instance is mandatory with one argument"
+ else:
+ cnf = Cnf(*args, **kwargs)
+
+ self.append(cnf)
+ return cnf
+
class BaseCnf:
"""Base class representing a CNF variable with minimal functionality."""
# support passing a Cnf instance
if len(args) == 1 and not kwargs:
cnf = args[0]
- assert isinstance(cnf, Cnf), \
- "With one argument, a Cnf instance is mandatory"
+ assert isinstance(cnf, Cnf), "A Cnf instance is mandatory with one argument"
else:
cnf = Cnf(*args, **kwargs)