装饰者#
有用的实用装饰师。
- @sympy.utilities.decorator.deprecated(message, *, deprecated_since_version, active_deprecations_target, stacklevel=3)[源代码]#
Mark a function as deprecated.
This decorator should be used if an entire function or class is deprecated. If only a certain functionality is deprecated, you should use
warns_deprecated_sympy()
directly. This decorator is just a convenience. There is no functional difference between using this decorator and callingwarns_deprecated_sympy()
at the top of the function.The decorator takes the same arguments as
warns_deprecated_sympy()
. See its documentation for details on what the keywords to this decorator do.See the Deprecation Policy document for details on when and how things should be deprecated in SymPy.
实例
>>> from sympy.utilities.decorator import deprecated >>> from sympy import simplify >>> @deprecated(""" ... The simplify_this(expr) function is deprecated. Use simplify(expr) ... instead.""", deprecated_since_version="1.1", ... active_deprecations_target='simplify-this-deprecation') ... def simplify_this(expr): ... """ ... Simplify ``expr``. ... ... .. deprecated:: 1.1 ... ... The ``simplify_this`` function is deprecated. Use :func:`simplify` ... instead. See its documentation for more information. See ... :ref:`simplify-this-deprecation` for details. ... ... """ ... return simplify(expr) >>> from sympy.abc import x >>> simplify_this(x*(x + 1) - x**2) <stdin>:1: SymPyDeprecationWarning: The simplify_this(expr) function is deprecated. Use simplify(expr) instead. See https://docs.sympy.org/latest/explanation/active-deprecations.html#simplify-this-deprecation for details. This has been deprecated since SymPy version 1.1. It will be removed in a future version of SymPy. simplify_this(x) x
- sympy.utilities.decorator.conserve_mpmath_dps(func)[源代码]#
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, python_version=None, ground_types=None)[源代码]#
添加有关在doctesting装饰对象的docstring时需要满足的依赖项的元数据。
exe
should be a list of executablesmodules
should be a list of modulesdisable_viewers
should be a list of viewers forpreview()
to disablepython_version
should be the minimum Python version required, as a tuple (like(3, 0)
)
- sympy.utilities.decorator.memoize_property(propfunc)[源代码]#
Property decorator that caches the value of potentially expensive
propfunc
after the first evaluation. The cached value is stored in the corresponding property name with an attached underscore.
- class sympy.utilities.decorator.no_attrs_in_subclass(cls, f)[源代码]#
不要从基类“继承”某些属性
>>> 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)[源代码]#
追加
obj
的名称改为全局__all__
变量(调用站点)。By using this decorator on functions or classes you achieve the same goal as by filling
__all__
variables manually, you just do not 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).注意,在多个decorator设置中(几乎在所有情况下)
@public
decorator必须在任何其他decorator之前应用,因为它依赖于指向对象全局命名空间的指针。如果你先申请其他装修师,@public
最终可能会修改错误的命名空间。实例
>>> from sympy.utilities.decorator import public
>>> __all__ # noqa: F821 Traceback (most recent call last): ... NameError: name '__all__' is not defined
>>> @public ... def some_function(): ... pass
>>> __all__ # noqa: F821 ['some_function']
- sympy.utilities.decorator.threaded(func)[源代码]#
应用
func
子对象的子元素,包括Add
.此修饰符旨在使将函数应用于复合对象的所有元素成为可能,例如矩阵、列表、元组和其他iterable容器,或仅用于表达式。
此版本的
threaded()
decorator允许在Add
班级。如果这种行为是不可取的xthreaded()
装饰者。使用此修饰符的函数必须具有以下签名:
@threaded def function(expr, *args, **kwargs):
- sympy.utilities.decorator.xthreaded(func)[源代码]#
应用
func
子对象的子元素,排除Add
.此修饰符旨在使将函数应用于复合对象的所有元素成为可能,例如矩阵、列表、元组和其他iterable容器,或仅用于表达式。
此版本的
threaded()
decorator不允许在Add
班级。如果这种行为是不可取的threaded()
装饰者。使用此修饰符的函数必须具有以下签名:
@xthreaded def function(expr, *args, **kwargs):