
    sgd+                         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 Z	d Z
d Zd Z G d	 d
      Z	 	 ddZd Zd ZdddZy)zUseful utility decorators.     N)wrapsupdate_wrappersympy_deprecation_warningc                 b     ddl m ddlm ddlm t                fd       }|S )z'A factory for ``threaded`` decorators. r   )sympify)
MatrixBase)iterablec           
         t        |       r| j                  fd      S  |       r*	 | j                  | D cg c]  } |gi  c}      S  |       } r=| j                  r1 | j                  | j
                  D cg c]  } |gi  c} S | j                  r:| j                   | j                  gi  | j                  gi       S  | gi S c c}w # t        $ r | cY S w xY wc c}w )Nc                      | gi S N )fargsfunckwargss    L/var/www/html/venv/lib/python3.12/site-packages/sympy/utilities/decorator.py<lambda>z9threaded_factory.<locals>.threaded_func.<locals>.<lambda>   s    D,DT,DV,D     )	
isinstance	applyfunc	__class__	TypeErroris_Addr   is_Relationallhsrhs)	exprr   r   r   r	   r   r
   r   use_adds	    `` r   threaded_funcz'threaded_factory.<locals>.threaded_func   s   dJ'>>"DEEd^~~&NAtA'?'?'?&NOO 4=D4;;%t~~499'Vaa)A$)A&)A'VWW##~~d488&Ed&Ef&E&*488&Ed&Ef&EG G D242622 'O  (Ws(   C6 C1C6 D1C6 6DD)
sympy.corer   sympy.matricesr	   sympy.utilities.iterablesr
   r   )r   r   r    r	   r
   r   s   `` @@@r   threaded_factoryr$   
   s*    ")2
4[3 3& r   c                     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   s    r   threadedr(   '   s    " D$''r   c                     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'   s    r   	xthreadedr*   ;   s    " D%((r   c                 6     ddl  f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                      j                   j                  }	  | i ||j                   _        S # |j                   _        w xY wr   )mpdps)r   r   r.   r   mpmaths      r   func_wrapperz)conserve_mpmath_dps.<locals>.func_wrapperT   s9    iimm	 ((FIIMCFIIMs	   2 A)r/   r   )r   r0   r/   s   ` @r   conserve_mpmath_dpsr1   O   s!       ",5Lr   c                       e Zd ZdZd ZddZy)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                      || _         || _        y r   )clsr   )selfr5   r   s      r   __init__zno_attrs_in_subclass.__init__r   s    r   Nc                     || j                   k(  r>t        | j                  d      r| j                  j                  ||      S | j                  S t        )N__get__)r5   hasattrr   r9   AttributeError)r6   instanceowners      r   r9   zno_attrs_in_subclass.__get__v   s@    DHHtvvy)vv~~h6666Mr   r   )__name__
__module____qualname____doc__r7   r9   r   r   r   r3   r3   _   s    $r   r3   c                 j    i | | d<   ||d<   ||d<   ||d<   ||d<   fdf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)``)
    executablesmodulesdisable_viewerspython_versionground_typesc                  v    ddl m} m}m}  |       } ||d       }	  |j                  di  y# | $ r Y yw xY w)Nr   )DependencyErrorSymPyDocTestsPyTestReporterFTr   )sympy.testing.runtestsrI   rJ   rK   _check_dependencies)rI   rJ   rK   rtdependenciess        r   	skiptestsz%doctest_depends_on.<locals>.skiptests   sN    YY!T"	!A!!1L1   		s   0 88c                     | _         | _        t        j                  |       r6t	        | | j                         | _        t	        | | j                        | _        | S r   )_doctest_depends_on__doctest_skip__inspectisclassr3   _doctest_depdends_on)fnrP   rQ   s    r   depends_on_decoz+doctest_depends_on.<locals>.depends_on_deco   sT    !-'??2&:B**',B#"6B''#)B	r   r   )exerD   rE   rF   rG   rY   rP   rQ   s         @@r   doctest_depends_onr[   ~   sm     L
&)]#")Y"*9&'!)7%&'3^$		 r   c                 n   t        | t        j                        r| j                  }| j                  }nat        | t        t
              t
        f      r4t        j                  | j                     j                  }| j                  }nt        d| z        d|vr|g|d<   | S |d   j                  |       | 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__r>   typesysrD   r?   __dict__r   append)objnsnames      r   publicrh      s    @ #u))*__||	C$t*d+	,[[(11||@3FGG9 J 	9T"Jr   c                 z     d j                   z   t               t                f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                 T    t        |       }|u r |       }t        | |       |S r   )getattrsetattr)r6   valattrnamepropfuncsentinels     r   accessorz"memoize_property.<locals>.accessor   s2    dHh/(?4.CD(C(
r   )r>   objectr   property)rp   rr   ro   rq   s   ` @@r   memoize_propertyru      s?     X&&&HxH
8_  Hr      )
stacklevelc                $     ||d f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                      t         d      r# G  fdd       } j                  |_        |S t                fd       } |_        |S )N__mro__c                        e Zd ZW j                  ZW j                  ZW ZdW j
                  v r fdZ xZS  fdZ xZS )9deprecated.<locals>.deprecated_decorator.<locals>.wrapper__new__c                 J    t        fi di t        |   | g|i |S Nrw   )r   superr   )r5   r   r   r   decorator_kwargsmessagerw   s      r   r   zAdeprecated.<locals>.deprecated_decorator.<locals>.wrapper.__new__>  s0    1'e=MeZde$wsDTDVDDr   c                 D    t        fi di t        |   |i | y r   )r   r   r7   )r6   r   r   r   r   r   rw   s      r   r7   zBdeprecated.<locals>.deprecated_decorator.<locals>.wrapper.__init__B  s)    1'e=MeZde($9&9r   )	r>   r?   r@   rA   _sympy_deprecated_funcrc   r   r7   __classcell__)r   r   r   rw   wrappeds   @r   wrapperr~   9  sA    !//$//
)0& 0 00E E: :r   r   c                  4    t        fi di  | i |S r   r   )r   r   r   r   rw   r   s     r   r   z9deprecated.<locals>.deprecated_decorator.<locals>.wrapperG  s'    )']5E]R\]///r   )r:   r>   r   r   )r   r   r   r   rw   s   ` r   deprecated_decoratorz(deprecated.<locals>.deprecated_decorator7  s\    7I&: :' :  '//G  7^0 0 .5G*r   r   )r   ry   rz   rw   r   r   s   `  ` @r   
deprecatedr      s#    @ 5M-GI,  r   )NNNNN)rA   rb   r^   rU   	functoolsr   r   sympy.utilities.exceptionsr   r$   r(   r*   r1   r3   r[   rh   ru   r   r   r   r   <module>r      s[    ! 
   + @:(()(  > @D9=1h.b& 78X r   