
    oVh+                         d Z ddlm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
  ed      Z	 d Zd Zd	 Zd
 Z G d d      Z	 	 ddZdedefdZd ZdddZy)zUseful utility decorators.     )TypeVarN)wrapsupdate_wrappersympy_deprecation_warningTc                 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    I/home/dcms/DCMS/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,   A   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   r0   r   mpmaths      r   func_wrapperz)conserve_mpmath_dps.<locals>.func_wrapperZ   s9    iimm	 ((FIIMCFIIMs	   2 A)r1   r   )r   r2   r1   s   ` @r   conserve_mpmath_dpsr3   U   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   )selfr7   r   s      r   __init__zno_attrs_in_subclass.__init__x   s    r   Nc                     || j                   k(  r>t        | j                  d      r| j                  j                  ||      S | j                  S t        )N__get__)r7   hasattrr   r;   AttributeError)r8   instanceowners      r   r;   zno_attrs_in_subclass.__get__|   s@    DHHtvvy)vv~~h6666Mr   r   )__name__
__module____qualname____doc__r9   r;   r   r   r   r5   r5   e   s    $r   r5   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.runtestsrK   rL   rM   _check_dependencies)rK   rL   rM   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isclassr5   _doctest_depdends_on)fnrR   rS   s    r   depends_on_decoz+doctest_depends_on.<locals>.depends_on_deco   sT    !-'??2&:B**',B#"6B''#)B	r   r   )exerF   rG   rH   rI   r[   rR   rS   s         @@r   doctest_depends_onr]      sm     L
&)]#")Y"*9&'!)7%&'3^$		 r   objreturnc                 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sysrF   rA   __dict__r   append)r^   nsnames      r   publicrk      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)r8   valattrnamepropfuncsentinels     r   accessorz"memoize_property.<locals>.accessor   s2    dHh/(?4.CD(C(
r   )r@   objectr   property)rs   ru   rr   rt   s   ` @@r   memoize_propertyrx      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 Nrz   )r   superr   )r7   r   r   r   decorator_kwargsmessagerz   s      r   r   zAdeprecated.<locals>.deprecated_decorator.<locals>.wrapper.__new__D  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   r9   )r8   r   r   r   r   r   rz   s      r   r9   zBdeprecated.<locals>.deprecated_decorator.<locals>.wrapper.__init__H  s)    1'e=MeZde($9&9r   )	r@   rA   rB   rC   _sympy_deprecated_funcrg   r   r9   __classcell__)r   r   r   rz   wrappeds   @r   wrapperr   ?  sA    !//$//
)0& 0 00E E: :r   r   c                  4    t        fi di  | i |S r   r   )r   r   r   r   rz   r   s     r   r   z9deprecated.<locals>.deprecated_decorator.<locals>.wrapperM  s'    )']5E]R\]///r   )r<   r@   r   r   )r   r   r   r   rz   s   ` r   deprecated_decoratorz(deprecated.<locals>.deprecated_decorator=  s\    7I&: :' :  '//G  7^0 0 .5G*r   r   )r   r|   r}   rz   r   r   s   `  ` @r   
deprecatedr      s#    @ 5M-GI,  r   )NNNNN)rC   typingr   rf   rb   rW   	functoolsr   r   sympy.utilities.exceptionsr   r   r&   r*   r,   r3   r5   r]   rk   rx   r   r   r   r   <module>r      sz    !  
   + @ CL :(()(  > @D9=1h. .a .b& 78X r   