qalgebra.printing.base module

Provides the base class for Printers

Summary

Classes:

QalgebraBasePrinter

Base class for all QAlgebra expression 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
  • cache (dict or None) – A dict that maps expressions to strings. It may be given during istantiation to use pre-defined strings for specific expressions. The cache will be updated as the printer is used.

  • settings (dict or None) – A dict of settings.

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. When doprint() 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

alias of qalgebra.printing.sympy.SympyStrPrinter

printmethod: str = None
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:

  1. from the Printer cache

  2. 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.

  3. Let the expr print itself if has the printmethod

  4. Take the best fitting _print_* method of the printer

  5. As fallback, delegate to emptyPrinter()

Any extra args or kwargs are passed to the internal _print method.