
    \h/                        % S SK Jr  S SKJr  S SKrSSKJrJrJrJ	r	  SSK
Jr  S SKr " S S\5      rS	 r " S
 S5      rS r\" 5       rS\S'   S/rS r\4S jr " S S5      rS r " S S\5      rS rS rg)    )annotations)warnN   )orderingambiguitiessuper_signatureAmbiguityWarning)expand_tuplesc                      \ rS rSrSrSrg)MDNotImplementedError
   z,A NotImplementedError for multiple dispatch  N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       Y/var/www/auris/envauris/lib/python3.13/site-packages/sympy/multipledispatch/dispatcher.pyr   r   
   s    7r   r   c                L    [        [        U R                  U5      [        5        g)a  Raise warning when ambiguity is detected

Parameters
----------
dispatcher : Dispatcher
    The dispatcher on which the ambiguity was detected
ambiguities : set
    Set of type signature pairs that are ambiguous within this dispatcher

See Also:
    Dispatcher.add
    warning_text
N)r   warning_textnamer	   )
dispatcherr   s     r   ambiguity_warnr      s     	joo{	35EFr   c                  $    \ rS rSrSrS rS rSrg)RaiseNotImplementedError!   z*Raise ``NotImplementedError`` when called.c                    Xl         g Nr   )selfr   s     r   __init__!RaiseNotImplementedError.__init__$   s    $r   c                    [        S U 5       5      n[        SU R                  R                  < S[	        U5      < S35      e)Nc              3  8   #    U  H  n[        U5      v   M     g 7fr    )type).0as     r   	<genexpr>4RaiseNotImplementedError.__call__.<locals>.<genexpr>(   s     ,t!d1ggt   zAmbiguous signature for : <>)tupleNotImplementedErrorr   r   str_signature)r"   argskwargstypess       r   __call__!RaiseNotImplementedError.__call__'   s8    ,t,,!OO  -"6
 	r   r!   N)r   r   r   r   r   r#   r5   r   r   r   r   r   r   !   s    4%r   r   c                    U HO  n[        [        U5      5      n[        [        U5      5      S:X  a  M1  U R	                  U[        U 5      [        S9  MQ     g)a  
If super signature for ambiguous types is duplicate types, ignore it.
Else, register instance of ``RaiseNotImplementedError`` for ambiguous types.

Parameters
----------
dispatcher : Dispatcher
    The dispatcher on which the ambiguity was detected
ambiguities : set
    Set of type signature pairs that are ambiguous within this dispatcher

See Also:
    Dispatcher.add
    ambiguity_warn
r   on_ambiguityN)r/   r   lensetaddr   #ambiguity_register_error_ignore_dup)r   r   amb	signatures       r   r=   r=   .   sP      /#./	s9~!#/
;< 	 	
	 r   zset[Dispatcher]_unresolved_dispatchersTc                     S[         S'   g )NFr   )_resolver   r   r   halt_orderingrC   N   s    HQKr   c                    S[         S'   [        (       a1  [        R                  5       nUR                  U S9  [        (       a  M0  g g )NTr   r8   )rB   r@   popreorder)r9   r   s     r   restart_orderingrG   R   s8    HQK
!
!,002
5 "
!r   c                      \ rS rSrSrSrSS jrS r\S 5       r	\S 5       r
\4S	 jr\4S
 jrS rS r\rS rS rS rS rS r\S 5       rS rS rS rS rSrg)
DispatcherY   a-  Dispatch methods based on type signature

Use ``dispatch`` to add implementations

Examples
--------

>>> from sympy.multipledispatch import dispatch
>>> @dispatch(int)
... def f(x):
...     return x + 1

>>> @dispatch(float)
... def f(x): # noqa: F811
...     return x - 1

>>> f(3)
4
>>> f(3.0)
2.0
)r   r   funcsr   _cachedocNc                V    U=U l         U l        0 U l        0 U l        / U l        X l        g r    )r   r   rK   rL   r   rM   )r"   r   rM   s      r   r#   Dispatcher.__init__q   s*    $((	DM
r   c                   ^ ^^ UU U4S jnU$ )a  Register dispatcher with new implementation

>>> from sympy.multipledispatch.dispatcher import Dispatcher
>>> f = Dispatcher('f')
>>> @f.register(int)
... def inc(x):
...     return x + 1

>>> @f.register(float)
... def dec(x):
...     return x - 1

>>> @f.register(list)
... @f.register(tuple)
... def reverse(x):
...     return x[::-1]

>>> f(1)
2

>>> f(1.0)
0.0

>>> f([1, 2, 3])
[3, 2, 1]
c                0   > TR                   " TU 40 TD6  U $ r    )r<   )funcr3   r"   r4   s    r   _Dispatcher.register.<locals>._   s    HHUD+F+Kr   r   )r"   r4   r3   rS   s   ``` r   registerDispatcher.registerx   s    6	 r   c                    [        [        S5      (       a0  [        R                  " U5      nUR                  R	                  5       $ g )Nr?   )hasattrinspectr?   
parametersvaluesclsrR   sigs      r   get_func_paramsDispatcher.get_func_params   s7    7K((##D)C>>((** )r   c                   ^ U R                  U5      nU(       aK  [        R                  mU4S jU 5       n[        S U 5       5      n[	        U4S jU 5       5      (       d  U$ gg)z:Get annotations of function positional parameters
        c              3  x   >#    U  H/  nUR                   TR                  TR                  4;   d  M+  Uv   M1     g 7fr    )kindPOSITIONAL_ONLYPOSITIONAL_OR_KEYWORD)r(   param	Parameters     r   r*   2Dispatcher.get_func_annotations.<locals>.<genexpr>   s;      9 00 6688 es   *:	:c              3  :   #    U  H  nUR                   v   M     g 7fr    )
annotation)r(   rf   s     r   r*   rh      s       %#E   #s   c              3  >   >#    U  H  oTR                   L v   M     g 7fr    )empty)r(   annrg   s     r   r*   rh      s     E#ioo-s   N)r_   rY   rg   r/   any)r]   rR   paramsr   rg   s       @r   get_func_annotationsDispatcher.get_func_annotations   sn     $$T*))I9 9F
    %# % %K EEEE"" F r   c           	        U(       d  U R                  U5      nU(       a  Un[        S U 5       5      (       a%  [        U5       H  nU R                  XRU5        M     gU HQ  n[	        U[
        5      (       a  M  SR                  S U 5       5      n[        SU< SU< SU R                  < 35      e   X R                  U'   U R                  US9  U R                  R                  5         g)	a  Add new types/method pair to dispatcher

>>> from sympy.multipledispatch import Dispatcher
>>> D = Dispatcher('add')
>>> D.add((int, int), lambda x, y: x + y)
>>> D.add((float, float), lambda x, y: x + y)

>>> D(1, 2)
3
>>> D(1, 2.0)
Traceback (most recent call last):
...
NotImplementedError: Could not find signature for add: <int, float>

When ``add`` detects a warning it calls the ``on_ambiguity`` callback
with a dispatcher/itself, and a set of ambiguous type signature pairs
as inputs.  See ``ambiguity_warn`` for an example.
c              3  B   #    U  H  n[        U[        5      v   M     g 7fr    )
isinstancer/   )r(   typs     r   r*   !Dispatcher.add.<locals>.<genexpr>   s     ;#z#u%%s   N, c              3  z   #    U  H1  n[        U[        5      (       a  UR                  O
[        U5      v   M3     g 7fr    )rt   r'   r   str)r(   cs     r   r*   rv      s4      $D9BA 3=Q2E2EAJJ),Q%09Bs   9;zTried to dispatch on non-type: z
In signature: <z>
In function: r8   )rp   rn   r
   r<   rt   r'   join	TypeErrorr   rK   rF   rL   clear)r"   r?   rR   r9   r   typsru   str_sigs           r   r<   Dispatcher.add   s    ( 33D9K'	 ;;;;%i0\2 1Cc4(()) $D9B$D D "%gtyy!: ; ;	  !%

9,/r   c                    [         S   (       a@  [        U R                  5      U l        [        U R                  5      nU(       a	  U" X5        g g [        R                  U 5        g )Nr   )rB   r   rK   r   r@   r<   )r"   r9   r>   s      r   rF   Dispatcher.reorder   sG    A;$TZZ0DMdjj)CT'  $''-r   c           	     &   [        U Vs/ s H  n[        U5      PM     sn5      n U R                  U   n U" U0 UD6$ s  snf ! [         aN    U R                  " U6 nU(       d'  [        SU R                  < S[        U5      < S35      eXPR                  U'    Nef = f! [         ag    U R                  " U6 n[        U5        U H  n U" U0 UD6s  s $ ! [         a     M  f = f   [        SU R                  < S[        U5      < S35      ef = f)NCould not find signature for r-   r.   zMatching functions for z(> found, but none completed successfully)r/   r'   rL   KeyErrordispatchr0   r   r1   r   dispatch_iternext)r"   r2   r3   argr4   rR   rK   s          r   r5   Dispatcher.__call__   s   D1DStCyD12	&;;u%D	K((( 2  	&==%(D)YYe 467 7 "&KK	& % 
	K&&.EK000,  
 &)-M%4H'J K K
	KsE   ?A B ABB)D	CD
C#D"C##-Dc                     SU R                   -  $ )Nz<dispatched %s>)r   r"   s    r   __str__Dispatcher.__str__  s     499,,r   c                    XR                   ;   a  U R                   U   $  [        U R                  " U6 5      $ ! [         a     gf = f)a  Deterimine appropriate implementation for this type signature

This method is internal.  Users should call this object as a function.
Implementation resolution occurs within the ``__call__`` method.

>>> from sympy.multipledispatch import dispatch
>>> @dispatch(int)
... def inc(x):
...     return x + 1

>>> implementation = inc.dispatch(int)
>>> implementation(3)
4

>>> print(inc.dispatch(float))
None

See Also:
    ``sympy.multipledispatch.conflict`` - module to determine resolution order
N)rK   r   r   StopIterationr"   r4   s     r   r   Dispatcher.dispatch  sJ    , JJ::e$$	**E233 		s   8 
AAc              '     #    [        U5      nU R                   HG  n[        U5      U:X  d  M  [        [        [        X5      5      (       d  M4  U R
                  U   nUv   MI     g 7fr    )r:   r   allmap
issubclassrK   )r"   r4   nr?   results        r   r   Dispatcher.dispatch_iter#  sL     JI9~"s3z5+L'M'MI. 's   (A&A&A&c                @    [        S[        5        U R                  " U6 $ )zzDeterimine appropriate implementation for this type signature

.. deprecated:: 0.4.4
    Use ``dispatch(*types)`` instead
z-resolve() is deprecated, use dispatch(*types))r   DeprecationWarningr   r   s     r   resolveDispatcher.resolve*  s#     	<	! }}e$$r   c                4    U R                   U R                  S.$ )Nr   rK   r   r   s    r   __getstate__Dispatcher.__getstate__5  s    		% 	%r   c                n    US   U l         US   U l        [        U R                  5      U l        0 U l        g )Nr   rK   )r   rK   r   rL   )r"   ds     r   __setstate__Dispatcher.__setstate__9  s/    fI	wZ
 ,r   c                <   SU R                   -  /nU R                  (       a  UR                  U R                  5        / nU R                  S S S2    H  nU R                  U   nUR
                  (       aQ  S[        U5      -  nUS[        U5      -  S-   -  nXTR
                  R                  5       -  nUR                  U5        Mt  UR                  [        U5      5        M     U(       a#  UR                  SSR                  U5      -   5        SR                  U5      $ )	NzMultiply dispatched method: %szInputs: <%s>
-
zOther signatures:
    z
    

)
r   rM   appendr   rK   r   r1   r:   stripr{   )r"   docsotherr^   rR   ss         r   r   Dispatcher.__doc__?  s    0499<=88KK!==2&C::c?D||$}S'99S3q6\D((\\''))A]3/0 ' KK1HMM%4HHI{{4  r   c                P    U R                   " [        [        U5      6 R                  $ r    )r   r   r'   r   )r"   r2   s     r   _helpDispatcher._helpV  s    }}c$o.666r   c                4    [        U R                  " U6 5        g)z9Print docstring for the function corresponding to inputs N)printr   r"   r2   r3   s      r   helpDispatcher.helpY  s    djj$ r   c                v    U R                   " [        [        U5      6 nU(       d  [        S5      e[	        U5      $ )NzNo function found)r   r   r'   r|   source)r"   r2   rR   s      r   _sourceDispatcher._source]  s/    }}c$o./00d|r   c                4    [        U R                  " U6 5        g)z;Print source code for the function corresponding to inputs N)r   r   r   s      r   r   Dispatcher.sourcec  s    dllD!"r   )r   rL   rM   rK   r   r   r    )r   r   r   r   r   	__slots__r#   rU   classmethodr_   rp   r   r<   rF   r5   r   __repr__r   r   r   r   r   propertyr   r   r   r   r   r   r   r   rI   rI   Y   s    * II@ + +
 # #& 1? *X $2 .K4-H<	%% ! !,7!#r   rI   c                j    S[         R                  " U 5      -  nU[         R                  " U 5      -   nU$ )Nz
File: %s

)rY   getsourcefile	getsource)rR   r   s     r   r   r   h  s1    ..t44A	Gd##AHr   c                  4    \ rS rSrSr\S 5       rS rS rSr	g)MethodDispatcherin  zCDispatch methods based on type signature

See Also:
    Dispatcher
c                    [        [        S5      (       aF  [        R                  " U5      n[        R                  " UR
                  R                  5       SS 5      $ g )Nr?   r   )rX   rY   r?   itlislicerZ   r[   r\   s      r   r_    MethodDispatcher.get_func_paramsu  sD    7K((##D)C::cnn335q$?? )r   c                    Xl         X l        U $ r    )objr]   )r"   instanceowners      r   __get__MethodDispatcher.__get__{  s    r   c                    [        U Vs/ s H  n[        U5      PM     sn5      nU R                  " U6 nU(       d'  [        SU R                  < S[        U5      < S35      eU" U R                  /UQ70 UD6$ s  snf )Nr   r-   r.   )r/   r'   r   r0   r   r1   r   )r"   r2   r3   r   r4   rR   s         r   r5   MethodDispatcher.__call__  sq    D1DStCyD12}}e$%'+yy-2F'H I IDHH.t.v.. 2s   A9)r]   r   N)
r   r   r   r   r   r   r_   r   r5   r   r   r   r   r   r   n  s'     @ @

/r   r   c                2    SR                  S U  5       5      $ )zString representation of type signature

>>> from sympy.multipledispatch.dispatcher import str_signature
>>> str_signature((int, float))
'int, float'
rw   c              3  8   #    U  H  oR                   v   M     g 7fr    )r   )r(   r]   s     r   r*    str_signature.<locals>.<genexpr>  s     1Sc\\Sr,   )r{   )r^   s    r   r1   r1     s     991S111r   c                   SU -  nUS-  nU H$  nUSSR                  S U 5       5      -   S-   -  nM&     US-  nUSR                  U Vs/ s H   nS	[        [        U5      5      -   S
U -  -   PM"     sn5      -  nU$ s  snf )z The text for ambiguity warnings z.
Ambiguities exist in dispatched function %s

z;The following signatures may result in ambiguous behavior:
	rw   c              3  D   #    U  H  nS [        U5      -   S-   v   M     g7f)[]N)r1   )r(   r   s     r   r*   warning_text.<locals>.<genexpr>  s     ADqcM!,,s2Ds    r   z,

Consider making the following additions:

r   z
@dispatch(z)
def %s(...))r{   r1   r   )r   r>   textpairr   s        r   r   r     s    >$GDJJDIIADAABDHI 	I  	>>DFKK<?A<?q &oa6H(II+d23<?A B BDKAs   
'A<
)
__future__r   warningsr   rY   conflictr   r   r   r	   utilsr
   	itertoolsr   r0   r   r   r   r=   r;   r@   __annotations__rB   rC   rG   rI   r   r   r1   r   r   r   r   <module>r      s    "   N N   8/ 8G" 
8 ,/5  06 #1 6L# L#^/z /62
r   