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.

Note

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

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.

Note

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.

>>> from tt import TruthTable
>>> try:
...     t = TruthTable('A or B', from_values='1111')
... except Exception as e:
...     print(type(e))
...
<class 'tt.errors.arguments.ConflictingArgumentsError'>
exception tt.errors.arguments.InvalidArgumentTypeError(message, *args)[source]

Bases: tt.errors.arguments.ArgumentError

An exception type for invalid argument types.

>>> from tt import TruthTable
>>> try:
...     t = TruthTable(7)
... except Exception as e:
...     print(type(e))
...
<class 'tt.errors.arguments.InvalidArgumentTypeError'>
exception tt.errors.arguments.InvalidArgumentValueError(message, *args)[source]

Bases: tt.errors.arguments.ArgumentError

An exception type for invalid argument values.

>>> from tt import TruthTable
>>> try:
...     t = TruthTable(from_values='01x')
... except Exception as e:
...     print(type(e))
...
<class 'tt.errors.arguments.InvalidArgumentValueError'>
exception tt.errors.arguments.RequiredArgumentError(message, *args)[source]

Bases: tt.errors.arguments.ArgumentError

An exception for when a required argument is missing.

>>> from tt import TruthTable
>>> try:
...     t = TruthTable()
... except Exception as e:
...     print(type(e))
...
<class 'tt.errors.arguments.RequiredArgumentError'>

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.

Note

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 an invalid truth or don’t care value passed.

>>> from tt import BooleanExpression
>>> try:
...     b = BooleanExpression('A or B')
...     b.evaluate(A=1, B='brian')
... except Exception as e:
...     print(type(e))
...
<class 'tt.errors.evaluation.InvalidBooleanValueError'>
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.

>>> from tt import TruthTable
>>> try:
...     t = TruthTable('1 or 0')
... except Exception as e:
...     print(type(e))
...
<class 'tt.errors.evaluation.NoEvaluationVariationError'>

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.

>>> from tt import BooleanExpression
>>> try:
...     b = BooleanExpression(') A or B')
... except Exception as e:
...     print(type(e))
...
<class 'tt.errors.grammar.BadParenPositionError'>
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.

>>> from tt import BooleanExpression
>>> try:
...     b = BooleanExpression('')
... except Exception as e:
...     print(type(e))
...
<class 'tt.errors.grammar.EmptyExpressionError'>
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.

>>> from tt import BooleanExpression
>>> try:
...     b = BooleanExpression('A or or B')
... except Exception as e:
...     print(type(e))
...
<class 'tt.errors.grammar.ExpressionOrderError'>
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.

Note

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

error_pos

The position in the expression where the error occurred.

Note

This may be left as None, in which case there is no specific location in the expression causing the exception.

Type:int
expr_str

The expression in which the exception occurred.

Note

This may be left as None, in which case 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.

>>> from tt import BooleanExpression, TruthTable
>>> b = BooleanExpression('%A or B')
Traceback (most recent call last):
    ...
tt.errors.grammar.InvalidIdentifierError: Invalid operand name "%A"
>>> t = TruthTable(from_values='0x11', ordering=['A', 'while'])
Traceback (most recent call last):
    ...
tt.errors.grammar.InvalidIdentifierError: "while" 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.

>>> from tt import BooleanExpression
>>> try:
...     b = BooleanExpression('A or ((B)')
... except Exception as e:
...     print(type(e))
...
<class 'tt.errors.grammar.UnbalancedParenError'>

errors.state module

Exception type definitions related to invalid operations based on state.

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.

>>> from tt import TruthTable
>>> try:
...     t = TruthTable('A or B', ordering=['A', 'A', 'B'])
... except Exception as e:
...     print(type(e))
...
<class 'tt.errors.symbols.DuplicateSymbolError'>
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.

>>> from tt import TruthTable
>>> try:
...     t = TruthTable('A or B', ordering=['A', 'B', 'C'])
... except Exception as e:
...     print(type(e))
...
<class 'tt.errors.symbols.ExtraSymbolError'>
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
>>> try:
...     b = BooleanExpression('A and B')
...     b.evaluate(A=1)
... except Exception as e:
...     print(type(e))
...
<class 'tt.errors.symbols.MissingSymbolError'>
exception tt.errors.symbols.SymbolError(message, *args)[source]

Bases: tt.errors.base.TtError

An exception for errors occurring in symbol processing.

Note

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