sympde package

Subpackages

Submodules

sympde.old_sympy_utilities module

Reimplementations of constructs introduced in later versions of Python than we support. Also some functions that are needed SymPy-wide and are located here for easy import.

class sympde.old_sympy_utilities.NotIterable[source]

Bases: object

Use this as mixin when creating a class which is not supposed to return true when iterable() is called on its instances because calling list() on the instance, for example, would result in an infinite loop.

sympde.old_sympy_utilities.is_sequence(i, include=None, *, vector=False)[source]

Return a boolean indicating whether i is a sequence in the SymPy sense. If anything that fails the test below should be included as being a sequence for your application, set ‘include’ to that object’s type; multiple types should be passed as a tuple of types.

Note: although generators can generate a sequence, they often need special handling to make sure their elements are captured before the generator is exhausted, so these are not included by default in the definition of a sequence.

See also: iterable

Examples

>>> from sympy.utilities.iterables import is_sequence
>>> from types import GeneratorType
>>> is_sequence([])
True
>>> is_sequence(set())
False
>>> is_sequence('abc')
False
>>> is_sequence('abc', include=str)
True
>>> generator = (c for c in 'abc')
>>> is_sequence(generator)
False
>>> is_sequence(generator, include=(str, GeneratorType))
True
sympde.old_sympy_utilities.iterable(i, exclude=(<class 'str'>, <class 'dict'>, <class 'sympde.old_sympy_utilities.NotIterable'>), vector=False)[source]

Return a boolean indicating whether i is SymPy iterable. True also indicates that the iterator is finite, e.g. you can call list(…) on the instance.

When SymPy is working with iterables, it is almost always assuming that the iterable is not a string or a mapping, so those are excluded by default. If you want a pure Python definition, make exclude=None. To exclude multiple items, pass them as a tuple.

You can also set the _iterable attribute to True or False on your class, which will override the checks here, including the exclude test.

As a rule of thumb, some SymPy functions use this to check if they should recursively map over an object. If an object is technically iterable in the Python sense but does not desire this behavior (e.g., because its iteration is not finite, or because iteration might induce an unwanted computation), it should disable it by setting the _iterable attribute to False.

See also: is_sequence

Examples

>>> from sympy.utilities.iterables import iterable
>>> from sympy import Tuple
>>> things = [[1], (1,), set([1]), Tuple(1), (j for j in [1, 2]), {1:2}, '1', 1]
>>> for i in things:
...     print('%s %s' % (iterable(i), type(i)))
True <... 'list'>
True <... 'tuple'>
True <... 'set'>
True <class 'sympy.core.containers.Tuple'>
True <... 'generator'>
False <... 'dict'>
False <... 'str'>
False <... 'int'>
>>> iterable({}, exclude=None)
True
>>> iterable({}, exclude=str)
True
>>> iterable("no", exclude=str)
False
sympde.old_sympy_utilities.with_metaclass(meta, *bases)[source]

Create a base class with a metaclass.

For example, if you have the metaclass

>>> class Meta(type):
...     pass

Use this as the metaclass by doing

>>> from sympde.old_sympy_utilities import with_metaclass
>>> class MyClass(with_metaclass(Meta, object)):
...     pass

This is equivalent to the Python 2:

class MyClass(object):
    __metaclass__ = Meta

or Python 3:

class MyClass(object, metaclass=Meta):
    pass

That is, the first argument is the metaclass, and the remaining arguments are the base classes. Note that if the base class is just object, you may omit it.

>>> MyClass.__mro__
(<class '...MyClass'>, <... 'object'>)
>>> type(MyClass)
<class '...Meta'>

sympde.version module

sympde.version.extract_version() → str[source]

Returns either the version of the installed package (e.g. “0.17.1”) or the one found in pyproject.toml (e.g. “0.17.1-dev (at /project/location)”).

Returns

str

The package version.

See also

https://stackoverflow.com/a/76206192

Module contents