Decorator

Useful utility decorators.

sympy.utilities.decorator.conserve_mpmath_dps(func)[source]

After the function finishes, resets the value of mpmath.mp.dps to the value it had before the function was run.

sympy.utilities.decorator.doctest_depends_on(exe=None, modules=None, disable_viewers=None)[source]

Adds metadata about the depenencies which need to be met for doctesting the docstrings of the decorated objects.

sympy.utilities.decorator.memoize_property(storage)[source]

Create a property, where the lookup is stored in storage

class sympy.utilities.decorator.no_attrs_in_subclass(cls, f)[source]

Don’t ‘inherit’ certain attributes from a base class

>>> from sympy.utilities.decorator import no_attrs_in_subclass
>>> class A(object):
...     x = 'test'
>>> A.x = no_attrs_in_subclass(A, A.x)
>>> class B(A):
...     pass
>>> hasattr(A, 'x')
True
>>> hasattr(B, 'x')
False
sympy.utilities.decorator.public(obj)[source]

Append obj’s name to global __all__ variable (call site).

By using this decorator on functions or classes you achieve the same goal as by filling __all__ variables manually, you just don’t have to repeat yourself (object’s name). You also know if object is public at definition site, not at some random location (where __all__ was set).

Note that in multiple decorator setup (in almost all cases) @public decorator must be applied before any other decorators, because it relies on the pointer to object’s global namespace. If you apply other decorators first, @public may end up modifying the wrong namespace.

Examples

>>> from sympy.utilities.decorator import public
>>> __all__
Traceback (most recent call last):
...
NameError: name '__all__' is not defined
>>> @public
... def some_function():
...     pass
>>> __all__
['some_function']
sympy.utilities.decorator.threaded(func)[source]

Apply func to sub–elements of an object, including Add.

This decorator is intended to make it uniformly possible to apply a function to all elements of composite objects, e.g. matrices, lists, tuples and other iterable containers, or just expressions.

This version of threaded() decorator allows threading over elements of Add class. If this behavior is not desirable use xthreaded() decorator.

Functions using this decorator must have the following signature:

@threaded
def function(expr, *args, **kwargs):
sympy.utilities.decorator.threaded_factory(func, use_add)[source]

A factory for threaded decorators.

sympy.utilities.decorator.xthreaded(func)[source]

Apply func to sub–elements of an object, excluding Add.

This decorator is intended to make it uniformly possible to apply a function to all elements of composite objects, e.g. matrices, lists, tuples and other iterable containers, or just expressions.

This version of threaded() decorator disallows threading over elements of Add class. If this behavior is not desirable use threaded() decorator.

Functions using this decorator must have the following signature:

@xthreaded
def function(expr, *args, **kwargs):