U
    L?hd+                     @   s   d Z ddlZddlZddlZddlmZmZ ddlmZ dd Z	dd Z
d	d
 Zdd ZG dd dZdddZdd Zdd ZddddZdS )zUseful utility decorators.     N)wrapsupdate_wrappersympy_deprecation_warningc                    sD   ddl m ddlm  ddlm t fdd}|S )z'A factory for ``threaded`` decorators. r   )sympify)
MatrixBase)iterablec                    s   t | r |  fddS | rbz|  fdd| D W S  tk
r^   |  Y S X nn| } r| jr| j fdd| jD  S | jr| | jf | jf S | f S d S )Nc                    s   | f S N )fargsfunckwargsr
   K/var/www/html/venv/lib/python3.8/site-packages/sympy/utilities/decorator.py<lambda>       z9threaded_factory.<locals>.threaded_func.<locals>.<lambda>c                    s   g | ]}|f qS r
   r
   .0r   r   r
   r   
<listcomp>   s     z;threaded_factory.<locals>.threaded_func.<locals>.<listcomp>c                    s   g | ]}|f qS r
   r
   r   r   r
   r   r      s     )	
isinstanceZ	applyfunc	__class__	TypeErrorZis_Addr   Zis_Relationallhsrhs)exprr   r   r   r   r   r   use_addr   r   r   threaded_func   s    

z'threaded_factory.<locals>.threaded_func)Z
sympy.corer   Zsympy.matricesr   Zsympy.utilities.iterablesr   r   )r   r   r   r
   r   r   threaded_factory
   s    r    c                 C   s
   t | dS )aU  Apply ``func`` to sub--elements of an object, including :class:`~.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 :func:`threaded` decorator allows threading over
    elements of :class:`~.Add` class. If this behavior is not desirable
    use :func:`xthreaded` decorator.

    Functions using this decorator must have the following signature::

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

    Tr    r   r
   r
   r   threaded'   s    r#   c                 C   s
   t | dS )aX  Apply ``func`` to sub--elements of an object, excluding :class:`~.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 :func:`threaded` decorator disallows threading over
    elements of :class:`~.Add` class. If this behavior is not desirable
    use :func:`threaded` decorator.

    Functions using this decorator must have the following signature::

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

    Fr!   r"   r
   r
   r   	xthreaded;   s    r$   c                    s$   ddl  fdd}t| }|S )zwAfter the function finishes, resets the value of ``mpmath.mp.dps`` to
    the value it had before the function was run.r   Nc                     s&   j j}z | |W S |j _X d S r	   )mpdps)r   r   r&   r   mpmathr
   r   func_wrapperT   s    z)conserve_mpmath_dps.<locals>.func_wrapper)r(   r   )r   r)   r
   r'   r   conserve_mpmath_dpsO   s    
r*   c                   @   s"   e Zd ZdZdd ZdddZdS )no_attrs_in_subclassaE  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

    c                 C   s   || _ || _d S r	   )clsr   )selfr,   r   r
   r
   r   __init__r   s    zno_attrs_in_subclass.__init__Nc                 C   s2   || j kr*t| jdr$| j||S | jS td S )N__get__)r,   hasattrr   r/   AttributeError)r-   instanceownerr
   r
   r   r/   v   s
    
zno_attrs_in_subclass.__get__)N)__name__
__module____qualname____doc__r.   r/   r
   r
   r
   r   r+   _   s   r+   c                    sr   i  | dk	r|  d< |dk	r$| d< |dk	r4| d< |dk	rD| d< |dk	rT| d<  fdd fd	d
}|S )a  
    Adds metadata about the dependencies which need to be met for doctesting
    the docstrings of the decorated objects.

    ``exe`` should be a list of executables

    ``modules`` should be a list of modules

    ``disable_viewers`` should be a list of viewers for :func:`~sympy.printing.preview.preview` to disable

    ``python_version`` should be the minimum Python version required, as a tuple
    (like ``(3, 0)``)
    NZexecutablesmodulesdisable_viewerspython_versionground_typesc                     sT   ddl m} m}m} | }||d }z|jf   W n | k
rJ   Y dS X dS d S )Nr   )DependencyErrorSymPyDocTestsPyTestReporterTF)Zsympy.testing.runtestsr<   r=   r>   Z_check_dependencies)r<   r=   r>   rt)dependenciesr
   r   	skiptests   s    
z%doctest_depends_on.<locals>.skiptestsc                    s6    | _ | _t| r2t| | j | _t| | j| _| S r	   )Z_doctest_depends_onZ__doctest_skip__inspectisclassr+   Z_doctest_depdends_on)fnrA   rB   r
   r   depends_on_deco   s    
  z+doctest_depends_on.<locals>.depends_on_decor
   )exer8   r9   r:   r;   rG   r
   rF   r   doctest_depends_on~   s    rI   c                 C   st   t | tjr| j}| j}n4t | tttfrBtj| j j	}| j}nt
d|  d|krb|g|d< n|d | | S )a  
    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 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).

    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__ # noqa: F821
    Traceback (most recent call last):
    ...
    NameError: name '__all__' is not defined

    >>> @public
    ... def some_function():
    ...     pass

    >>> __all__ # noqa: F821
    ['some_function']

    z&expected a function or a class, got %s__all__)r   typesFunctionType__globals__r4   typesysr8   r5   __dict__r   append)objnsnamer
   r
   r   public   s     rU   c                    s0   dj   t t fdd}t|S )zProperty 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._c                    s,   t |  }|kr(| }t|  | |S r	   )getattrsetattr)r-   valattrnamepropfuncsentinelr
   r   accessor   s
    z"memoize_property.<locals>.accessor)r4   objectr   property)r\   r^   r
   rZ   r   memoize_property   s
    
ra      )
stacklevelc                   s   ||d  fdd}|S )a  
    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
    :func:`~.warns_deprecated_sympy` directly. This decorator is just a
    convenience. There is no functional difference between using this
    decorator and calling ``warns_deprecated_sympy()`` at the top of the
    function.

    The decorator takes the same arguments as
    :func:`~.warns_deprecated_sympy`. See its
    documentation for details on what the keywords to this decorator do.

    See the :ref:`deprecation-policy` document for details on when and how
    things should be deprecated in SymPy.

    Examples
    ========

    >>> 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) # doctest: +SKIP
    <stdin>:1: SymPyDeprecationWarning:
    <BLANKLINE>
    The simplify_this(expr) function is deprecated. Use simplify(expr)
    instead.
    <BLANKLINE>
    See https://docs.sympy.org/latest/explanation/active-deprecations.html#simplify-this-deprecation
    for details.
    <BLANKLINE>
    This has been deprecated since SymPy version 1.1. It
    will be removed in a future version of SymPy.
    <BLANKLINE>
      simplify_this(x)
    x

    See Also
    ========
    sympy.utilities.exceptions.SymPyDeprecationWarning
    sympy.utilities.exceptions.sympy_deprecation_warning
    sympy.utilities.exceptions.ignore_warnings
    sympy.testing.pytest.warns_deprecated_sympy

    )deprecated_since_versionactive_deprecations_targetc                    sR   t  dr.G  fddd } j|_n t  fdd} |_|S )N__mro__c                       sP   e Zd ZjZjZZdjkr6 fddZn fddZ  ZS )9deprecated.<locals>.deprecated_decorator.<locals>.wrapper__new__c                    s(   t fdi t j| f||S Nrc   )r   superrh   )r,   r   r   r   decorator_kwargsmessagerc   r
   r   rh   >  s    zAdeprecated.<locals>.deprecated_decorator.<locals>.wrapper.__new__c                    s&   t fdi t j|| d S ri   )r   rj   r.   )r-   r   r   rk   r
   r   r.   B  s    zBdeprecated.<locals>.deprecated_decorator.<locals>.wrapper.__init__)	r4   r5   r6   r7   _sympy_deprecated_funcrP   rh   r.   __classcell__r
   rl   rm   rc   wrapped)r   r   wrapper9  s   
rr   c                     s   t f di | |S ri   r   r   rp   r
   r   rr   G  s    rg   )r0   r4   r   rn   )rq   rr   rl   rm   rc   )rq   r   deprecated_decorator7  s    

z(deprecated.<locals>.deprecated_decoratorr
   )rm   rd   re   rc   rt   r
   rs   r   
deprecated   s
    @ru   )NNNNN)r7   rO   rK   rC   	functoolsr   r   Zsympy.utilities.exceptionsr   r    r#   r$   r*   r+   rI   rU   ra   ru   r
   r
   r
   r   <module>   s$       
41