qalgebra.printing.base module¶
Provides the base class for Printers
Reference¶
-
class
qalgebra.printing.base.
QalgebraBasePrinter
(cache=None, settings=None)[source]¶ Bases:
sympy.printing.printer.Printer
Base class for all QAlgebra expression printers
- Parameters
- Class Attributes
sympy_printer_cls (type) – The class that will be instantiated to print Sympy expressions
_default_settings (dict) – The default value of all settings. Note only settings for which there are defaults defined here are accepted when instantiating the printer
printmethod (None or str) – Name of a method that expressions may define to print themeselves.
- Attributes
cache (dict) – Dictionary where the results of any call to
doprint()
is stored. Whendoprint()
is called for an expression that is already in cache, the result from the cache is returned._sympy_printer (sympy.printing.printer.Printer) – The printer instance that will be used to print any Sympy expression.
_allow_caching (bool) – A flag that may be set to completely disable caching
_print_level (int) – The recursion depth of
doprint()
(>= 1 inside any of the_print*
methods)
- Raises
TypeError – If any key in settings is not defined in the _default_settings of the printer, respectively the sympy_printer_cls.
-
sympy_printer_cls
¶
-
emptyPrinter
(expr)[source]¶ Fallback method for expressions that neither know how to print themeselves, nor for which the printer has a suitable
_print*
method
-
doprint
(expr, *args, **kwargs)[source]¶ Returns printer’s representation for expr (as a string)
The representation is obtained by the following methods:
from the Printer cache
If expr is a Sympy object, delegate to the
doprint()
method of the SymPy printer referenced by the QAlgebra printer’s_sympy_printer
class attribute.Let the expr print itself if has the
printmethod
Take the best fitting
_print_*
method of the printerAs fallback, delegate to
emptyPrinter()
Any extra args or kwargs are passed to the internal _print method.