errors

tt error types.

errors.base module

The base tt exception type.

exception tt.errors.base.TtError(message, *args)[source]

Bases: Exception

Base exception type for tt errors. This exception type should be sub-classed and is not meant to be raised explicitly.

__init__(message, *args)[source]

Initialize self. See help(type(self)) for accurate signature.

message

A helpful message intended to be shown to the end user.

Type:str

errors.arguments module

Generic exception types.

exception tt.errors.arguments.ArgumentError(message, *args)[source]

Bases: tt.errors.base.TtError

An exception type for invalid arguments. This exception type should be sub-classed and is not meant to be raised explicitly.

exception tt.errors.arguments.ConflictingArgumentsError(message, *args)[source]

Bases: tt.errors.arguments.ArgumentError

An exception type for two or more conflicting arguments.

This error type can be seen in action by passing both an expression and a set of values to the TruthTable class:

>>> from tt import TruthTable
>>> t = TruthTable('A or B', from_values='1111')
Traceback (most recent call last):
    ...
tt.errors.arguments.ConflictingArgumentsError: `expr` and `from_values` are mutually exclusive arguments
exception tt.errors.arguments.InvalidArgumentTypeError(message, *args)[source]

Bases: tt.errors.arguments.ArgumentError

An exception type for invalid argument types.

To illustrate this error type, let’s try passing an invalid argument when creating a TruthTable:

>>> from tt import TruthTable
>>> t = TruthTable(7)
Traceback (most recent call last):
    ...
tt.errors.arguments.InvalidArgumentTypeError: Arg `expr` must be of type `str` or `BooleanExpression`
exception tt.errors.arguments.InvalidArgumentValueError(message, *args)[source]

Bases: tt.errors.arguments.ArgumentError

An exception type for invalid argument values.

Here’s an example where we pass a non-power of 2 number of values when attempting to create a TruthTable:

>>> from tt import TruthTable
>>> t = TruthTable(from_values='01x')
Traceback (most recent call last):
    ...
tt.errors.arguments.InvalidArgumentValueError: Must specify a number of input values that is a power of 2
exception tt.errors.arguments.RequiredArgumentError(message, *args)[source]

Bases: tt.errors.arguments.ArgumentError

An exception for when a required argument is missing.

Let’s try an example where we omit all arguments when attempting to make a new TruthTable object:

>>> from tt import TruthTable
>>> t = TruthTable()
Traceback (most recent call last):
    ...
tt.errors.arguments.RequiredArgumentError: Must specify either `expr` or `from_values`

errors.evaluation module

Exception type definitions related to expression evaluation.

exception tt.errors.evaluation.EvaluationError(message, *args)[source]

Bases: tt.errors.base.TtError

An exception type for errors occurring in expression evaluation. This exception type should be sub-classed and is not meant to be raised explicitly.

exception tt.errors.evaluation.InvalidBooleanValueError(message, *args)[source]

Bases: tt.errors.evaluation.EvaluationError

An exception for when an invalid truth or don’t care value is passed.

Here’s an example where we attempt to evaluate a BooleanExpression with an invalid value passed through kwargs:

>>> from tt import BooleanExpression
>>> b = BooleanExpression('A or B')
>>> b.evaluate(A=1, B='brian')
Traceback (most recent call last):
    ...
tt.errors.evaluation.InvalidBooleanValueError: "brian" passed as value for "B" is not a valid Boolean value
exception tt.errors.evaluation.NoEvaluationVariationError(message, *args)[source]

Bases: tt.errors.evaluation.EvaluationError

An exception type for when evaluation of an expression will not vary.

Let’s see an example where we attempt to make a TruthTable from an expression that has no symbols nor variation in its results:

>>> from tt import TruthTable
>>> t = TruthTable('1 or 0')
Traceback (most recent call last):
    ...
tt.errors.evaluation.NoEvaluationVariationError: This expression is composed only of constant values

errors.grammar module

Exception type definitions related to expression grammar and parsing.

exception tt.errors.grammar.BadParenPositionError(message, expr_str=None, error_pos=None, *args)[source]

Bases: tt.errors.grammar.GrammarError

An exception type for unexpected parentheses.

Here’s a quick and dirty example:

>>> from tt import BooleanExpression
>>> b = BooleanExpression('A or B (')
Traceback (most recent call last):
    ...
tt.errors.grammar.BadParenPositionError: Unexpected parenthesis
exception tt.errors.grammar.EmptyExpressionError(message, expr_str=None, error_pos=None, *args)[source]

Bases: tt.errors.grammar.GrammarError

An exception type for when an empty expression is received.

Let’s take a brief look:

>>> from tt import BooleanExpression
>>> b = BooleanExpression('')
Traceback (most recent call last):
    ...
tt.errors.grammar.EmptyExpressionError: Empty expression is invalid
exception tt.errors.grammar.ExpressionOrderError(message, expr_str=None, error_pos=None, *args)[source]

Bases: tt.errors.grammar.GrammarError

An exception type for unexpected operands or operators.

Here’s an example with an unexpected operator:

>>> from tt import BooleanExpression
>>> b = BooleanExpression('A or or B')
Traceback (most recent call last):
    ...
tt.errors.grammar.ExpressionOrderError: Unexpected binary operator "or"
exception tt.errors.grammar.GrammarError(message, expr_str=None, error_pos=None, *args)[source]

Bases: tt.errors.base.TtError

Base type for errors that occur in the handling of expression. This exception type should be sub-classed and is not meant to be raised explicitly.

__init__(message, expr_str=None, error_pos=None, *args)[source]

Initialize self. See help(type(self)) for accurate signature.

error_pos

The position in the expression where the error occurred.

If this property is left as None, it can be assumed that there is no specific location in the expression causing the exception.

Type:int
expr_str

The expression in which the exception occurred.

If this property is left as None, the expression will not be propagated with the exception.

Type:str
exception tt.errors.grammar.InvalidIdentifierError(message, expr_str=None, error_pos=None, *args)[source]

Bases: tt.errors.grammar.GrammarError

An exception type for invalid operand names. Invalid operand names are determined via the is_valid_identifier function.

Here are a couple of examples, for both expressions and tables:

>>> from tt import BooleanExpression, TruthTable
>>> b = BooleanExpression('__A xor B')
Traceback (most recent call last):
    ...
tt.errors.grammar.InvalidIdentifierError: Invalid operand name "__A"
>>> t = TruthTable(from_values='0x11', ordering=['for', 'operand'])
Traceback (most recent call last):
    ...
tt.errors.grammar.InvalidIdentifierError: "for" in ordering is not a     valid symbol name
exception tt.errors.grammar.UnbalancedParenError(message, expr_str=None, error_pos=None, *args)[source]

Bases: tt.errors.grammar.GrammarError

An exception type for unbalanced parentheses.

Here’s a short example:

>>> from tt import BooleanExpression
>>> b = BooleanExpression('A or B or C)')
Traceback (most recent call last):
    ...
tt.errors.grammar.UnbalancedParenError: Unbalanced parenthesis

errors.state module

Exception type definitions related to invalid operations based on state.

exception tt.errors.state.AlreadyConstrainedSymbolError(message, *args)[source]

Bases: tt.errors.state.StateError

An exception to be raised when trying to doubly constrain a symbol.

>>> from tt import BooleanExpression
>>> b = BooleanExpression('A or B or C')
>>> with b.constrain(C=1):
...     with b.constrain(C=0):
...         pass
...
Traceback (most recent call last):
tt.errors.state.AlreadyConstrainedSymbolError: Symbol "C" cannot be constrained multiple times
exception tt.errors.state.AlreadyFullTableError(message, *args)[source]

Bases: tt.errors.state.StateError

An exception to be raised when attempting to fill an already-full table.

>>> from tt import TruthTable
>>> t = TruthTable('A or B', fill_all=False)
>>> t.fill()
>>> t.is_full
True
>>> t.fill()
Traceback (most recent call last):
tt.errors.state.AlreadyFullTableError: Cannot fill an already-full table
exception tt.errors.state.RequiresFullTableError(message, *args)[source]

Bases: tt.errors.state.StateError

An exception to be raised when a full table is required.

>>> from tt import TruthTable
>>> t = TruthTable('A or B', fill_all=False)
>>> t.equivalent_to('A or B')
Traceback (most recent call last):
tt.errors.state.RequiresFullTableError: Equivalence can only be checked on full truth tables
exception tt.errors.state.RequiresNormalFormError(message, *args)[source]

Bases: tt.errors.state.StateError

An exception to be raised when expression normal form is required.

>>> from tt import BooleanExpression
>>> b = BooleanExpression('A nand (B or C)')
>>> b.is_cnf or b.is_dnf
False
>>> for clause in b.iter_clauses():
...     print(clause)
...
Traceback (most recent call last):
tt.errors.state.RequiresNormalFormError: Must be in conjunctive or disjunctive normal form to iterate clauses
exception tt.errors.state.StateError(message, *args)[source]

Bases: tt.errors.base.TtError

Base exception type for errors involving invalid state.

errors.symbols module

Exception types related to symbol processing.

exception tt.errors.symbols.DuplicateSymbolError(message, *args)[source]

Bases: tt.errors.symbols.SymbolError

An exception type for user-specified duplicate symbols.

Here’s an example where we try to pass duplicate symbols to the ordering property of the TruthTable class:

>>> from tt import TruthTable
>>> t = TruthTable('A or B', ordering=['A', 'A', 'B'])
Traceback (most recent call last):
    ...
tt.errors.symbols.DuplicateSymbolError: Received duplicate symbols
exception tt.errors.symbols.ExtraSymbolError(message, *args)[source]

Bases: tt.errors.symbols.SymbolError

An exception for a passed token that is not a parsed symbol.

Here’s a quick table example:

>>> from tt import TruthTable
>>> t = TruthTable('A or B', ordering=['A', 'B', 'C'])
Traceback (most recent call last):
    ...
tt.errors.symbols.ExtraSymbolError: Received unexpected symbols: "C"
exception tt.errors.symbols.MissingSymbolError(message, *args)[source]

Bases: tt.errors.symbols.SymbolError

An exception type for a missing token value in evaluation.

>>> from tt import BooleanExpression
>>> b = BooleanExpression('A and B')
>>> b.evaluate(A=1)
Traceback (most recent call last):
    ...
tt.errors.symbols.MissingSymbolError: Did not receive value for the following symbols: "B"
exception tt.errors.symbols.SymbolError(message, *args)[source]

Bases: tt.errors.base.TtError

An exception for errors occurring in symbol processing. This exception type should be sub-classed and is not meant to be raised explicitly.