
    $TXg=                       d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	m
Z
 ddlmZ er9ddlmZmZ dd	lmZmZmZmZmZ dd
lmZ  ed      Z ed      Z edee         ZddlmZ  G d de      Z G d d      Z ee      Zy)z!Tools to aid in deprecating code.    )annotationsN)Action)wraps)
ModuleType)TYPE_CHECKING)ArgumentParser	Namespace)AnyCallable	ParamSpecSelfTypeVar)VersionTP
ActionType)bound   )__version__c                      e Zd Zy)DeprecatedErrorN)__name__
__module____qualname__     2lib/python3.12/site-packages/conda/deprecations.pyr   r      s    r   r   c                     e Zd ZU ded<   ded<   ded<   ddZedd       Zdd	Zd
ded	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	d
d
ded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
d
ded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZd
dd	 	 	 	 	 	 	 	 	 	 	 ddZd
ded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZd
ded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZd dZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZy
)"DeprecationHandler
str | None_versiontuple[int, ...] | None_version_tuplezVersion | None_version_objectc                L    || _         | j                  |      | _        d| _        y)zFactory to create a deprecation handle for the specified version.

        :param version: The version to compare against when checking deprecation statuses.
        N)r!   _get_version_tupler#   r$   )selfversions     r   __init__zDeprecationHandler.__init__'   s(    
   #55g>#r   c                    	 t        d | j                         j                  d      D              xs dS # t        t        f$ r Y yw xY w)z|Return version as non-empty tuple of ints if possible, else None.

        :param version: Version string to parse.
        c              3  2   K   | ]  }t        |        y wN)int).0parts     r   	<genexpr>z8DeprecationHandler._get_version_tuple.<locals>.<genexpr>9   s     J/ItT/Is   .N)tuplestripsplitAttributeError
ValueError)r(   s    r   r&   z%DeprecationHandler._get_version_tuple2   sE    	Jw}}/D/DS/IJJRdR
+ 		s   25 AAc                   | j                   r"| j                  |      x}r| j                   |k  S ddlm} | j                  	  || j
                        | _        | j                   ||      k  S # t        $ r  |d      | _        Y -w xY w)z}Test whether own version is less than the given version.

        :param version: Version string to compare against.
        r   )parsez0.0.0.dev0+placeholder)r#   r&   packaging.versionr8   r$   r!   	TypeError)r'   r(   version_tupler8   s       r   _version_less_thanz%DeprecationHandler._version_less_than=   s    
 T5L5LW5U$UM$U&&66
 	,'G',T]]';$ ##eGn44  G',-E'F$Gs   A. .BBNr   )addendumstackdeprecation_typec               (     d fd}|S )ar  Deprecation decorator for functions, methods, & classes.

        :param deprecate_in: Version in which code will be marked as deprecated.
        :param remove_in: Version in which code is expected to be removed.
        :param addendum: Optional additional messaging. Useful to indicate what to do instead.
        :param stack: Optional stacklevel increment.
        c                     j                   j                   d j                         \  st              t	               d 	fd       }|S )Nr1   deprecate_in	remove_inprefixr=   r?   c                 J    t        j                  dz           | i |S N   
stacklevel)warningswarn)argskwargscategoryfuncmessager>   s     r   innerzHDeprecationHandler.__call__.<locals>.deprecated_decorator.<locals>.innerr   s'    gxAIFT,V,,r   rM   zP.argsrN   zP.kwargsreturnr   _generate_messager   r   r   r   )
rP   rR   rO   rQ   r=   rC   r?   rD   r'   r>   s
   ` @@r   deprecated_decoratorz9DeprecationHandler.__call__.<locals>.deprecated_decoratorc   sr     $ 6 6)#//*!D,=,=+>?!!1 !7 !Hg %g.. 4[- -
 Lr   rP   Callable[P, T]rT   rY   r   )r'   rC   rD   r=   r>   r?   rW   s   `````` r   __call__zDeprecationHandler.__call__R   s    "	 	. $#r   )renamer=   r>   r?   c          	     0     d fd}|S )a  Deprecation decorator for keyword arguments.

        :param deprecate_in: Version in which code will be marked as deprecated.
        :param remove_in: Version in which code is expected to be removed.
        :param argument: The argument to deprecate.
        :param rename: Optional new argument name.
        :param addendum: Optional additional messaging. Useful to indicate what to do instead.
        :param stack: Optional stacklevel increment.
        c           
          
j                   j                   d j                   d d	rsd	 dn      \  st              t	               d 	fd       }|S )	Nr1   ()zUse 'z
' instead.rB   c                     |v rAt        j                  dz          |j                  d       }r|j                  |        | i |S rG   )rK   rL   pop
setdefault)	rM   rN   valueargumentrO   rP   rQ   r[   r>   s	      r   rR   zHDeprecationHandler.argument.<locals>.deprecated_decorator.<locals>.inner   sV     v%MM'8E	J #JJx6E))&%8T,V,,r   rS   rU   )rP   rR   rO   rQ   r=   rd   rC   r?   rD   r[   r'   r>   s   ` @@r   rW   z9DeprecationHandler.argument.<locals>.deprecated_decorator   s     $ 6 6)#//*!D,=,=+>azK 39eF8:.x!1 !7 	!Hg %g.. 4[
- 
- 
- Lr   rX   r   )	r'   rC   rD   rd   r[   r=   r>   r?   rW   s	   ```````` r   rd   zDeprecationHandler.argument|   s    *	 	B $#r   c               l      G  fddt               }t        |j                  ||fi       S )z9Wraps any argparse.Action to issue a deprecation warning.c                  j     e Zd ZU ded<   ded<   d fdZ	 d	 	 	 	 	 	 	 	 	 	 	 d	 fdZ xZS )
3DeprecationHandler.action.<locals>.DeprecationMixintype[Warning]rO   strhelpc                    t        |   |i | 
j                  	| j                  rd| j                  d    dnd| j                   d      \  }}|st        |      || _        || _        y )N`rB   )superr)   rV   option_stringsdestr   rO   rj   )
inner_selfrM   rN   rO   rQ   	__class__r=   rC   r?   rD   r'   s        r   r)   z<DeprecationHandler.action.<locals>.DeprecationMixin.__init__   s     $1&1$($:$:!-'
 &44 J55b9:!<  ! 13%%5 %; %!'   )'22&.
#")
r   c                    |r/t        j                  | j                  | j                  dz          t        |   ||||       y )N   rI   )rK   rL   rj   rO   rn   rZ   )rq   parser	namespacevaluesoption_stringrr   r>   s        r   rZ   z<DeprecationHandler.action.<locals>.DeprecationMixin.__call__   s@     MM""++#$u9  FMJr   )rq   r   rM   r
   rN   r
   rT   Noner,   )rq   r   ru   r   rv   r	   rw   r
   rx   r    rT   ry   )r   r   r   __annotations__r)   rZ   __classcell__)rr   r=   rC   r?   rD   r'   r>   s   @r   DeprecationMixinrg      sg    ##I* *< -1K K&K %K 	K
  *K K Kr   r|   )r   typer   )r'   rC   rD   actionr=   r>   r?   r|   s   ``` ``` r   r~   zDeprecationHandler.action   s3    ,	K ,	Kv ,	K\ FOO&6%?DDr   )r=   r>   c               Z    | j                  ||| j                  |      d   |d|z          y)a[  Deprecation function for modules.

        :param deprecate_in: Version in which code will be marked as deprecated.
        :param remove_in: Version in which code is expected to be removed.
        :param addendum: Optional additional messaging. Useful to indicate what to do instead.
        :param stack: Optional stacklevel increment.
        r   rH   )rC   rD   topicr=   r>   N)r   _get_module)r'   rC   rD   r=   r>   s        r   modulezDeprecationHandler.module   s8     	

%""5)!,e) 	 	
r   c                  
 | j                        \  }| j                  || d ||      \  

st              t        |dd      d
fd}	|	|_        y)a  Deprecation function for module constant/global.

        :param deprecate_in: Version in which code will be marked as deprecated.
        :param remove_in: Version in which code is expected to be removed.
        :param constant:
        :param value:
        :param addendum: Optional additional messaging. Useful to indicate what to do instead.
        :param stack: Optional stacklevel increment.
        r1   rB   __getattr__Nc                    | k(  rt        j                  dz          S r |       S t        d d|  d      )N   rI   zmodule 'z' has no attribute '')rK   rL   r5   )namerO   constantfullnamerQ   r>   super_getattrrc   s    r   r   z0DeprecationHandler.constant.<locals>.__getattr__-  sM    xgxAIF$T** 8H:5I$q!QRRr   )r   ri   rT   r
   )r   rV   r   getattrr   )r'   rC   rD   r   rc   r=   r>   r?   r   r   rO   r   rQ   r   s      `` `   @@@@r   r   zDeprecationHandler.constant  s    *  ++E2 22%Zq
+- 3 
' !'**  t<	S 	S )r   c                   | j                  |||||      \  }}|st        |      t        j                  ||d|z          y)a  Deprecation function for a topic.

        :param deprecate_in: Version in which code will be marked as deprecated.
        :param remove_in: Version in which code is expected to be removed.
        :param topic: The topic being deprecated.
        :param addendum: Optional additional messaging. Useful to indicate what to do instead.
        :param stack: Optional stacklevel increment.
        rB   rH   rI   N)rV   r   rK   rL   )	r'   rC   rD   r   r=   r>   r?   rO   rQ   s	            r   r   zDeprecationHandler.topic9  sS    & !22%- 3 
' !'** 	gxAI>r   c                   	 t        j                  d|z         }	 |j                  j                  }t	        t         j
                  j                               D ]?  }t        |t              st        |d      s!|j                  |k(  s1||j                  fc S  	 ddl}|j                  |      }|||j                  fS t!        d      # t        $ r Y ;w xY w# t        $ r Y t!        d      w xY w)zDetect the module from which we are being called.

        :param stack: The stacklevel increment.
        :return: The module and module name.
        rH   __file__r   Nz&unable to determine the calling module)sys	_getframef_codeco_filenamer2   modulesrw   
isinstancer   hasattrr   r   r5   inspect	getmodule
IndexErrorr   )r'   r>   framefilenameloadedr   r   s          r   r   zDeprecationHandler._get_module[  s    	1MM!e),E9 <<33 $CKK$6$6$89F%fj9 "6:6 (2 &88 : &&u-F!00FGG+ "   	4 FGG9	s"   C C 	CC	C0/C0c          	         | j                  |      rt        }d| d}n"| j                  |      r	|}d| d}nd}d| d}|dj                  t        d|||g            fS )aS  Generate the standardized deprecation message and determine whether the
        deprecation is pending, active, or past.

        :param deprecate_in: Version in which code will be marked as deprecated.
        :param remove_in: Version in which code is expected to be removed.
        :param prefix: The message prefix, usually the function name.
        :param addendum: Additional messaging. Useful to indicate what to do instead.
        :param deprecation_type: The warning type to use for active deprecations.
        :return: The warning category (if applicable) and the message.
        z.is pending deprecation and will be removed in r1   z%is deprecated and will be removed in Nzwas slated for removal in  )r<   PendingDeprecationWarningjoinfilter)r'   rC   rD   rE   r=   r?   rO   warnings           r   rV   z$DeprecationHandler._generate_message  s    ( ""<00HFykQRSG$$Y/'H=i[JGH29+Q?G HHVD67H"=>?
 	
r   )r'   r   r(   ri   rT   ry   )r(   ri   rT   r"   )r'   r   r(   ri   rT   bool)r'   r   rC   ri   rD   ri   r=   r    r>   r-   r?   rh   rT   *Callable[[Callable[P, T]], Callable[P, T]])r'   r   rC   ri   rD   ri   rd   ri   r[   r    r=   r    r>   r-   r?   rh   rT   r   )r'   r   rC   ri   rD   ri   r~   r   r=   r    r>   r-   r?   rh   rT   r   )r'   r   rC   ri   rD   ri   r=   r    r>   r-   rT   ry   )r'   r   rC   ri   rD   ri   r   ri   rc   r
   r=   r    r>   r-   r?   rh   rT   ry   )r'   r   rC   ri   rD   ri   r   ri   r=   r    r>   r-   r?   rh   rT   ry   )r'   r   r>   r-   rT   ztuple[ModuleType, str])r'   r   rC   ri   rD   ri   rE   ri   r=   r    r?   rh   rT   z tuple[type[Warning] | None, str])r   r   r   rz   r)   staticmethodr&   r<   DeprecationWarningrZ   rd   FutureWarningr~   r   r   r   r   rV   r   r   r   r   r   "   s   **##	$  54  $*<($($($ ($
 ($ ($ (($ 
4($` "#*<6$6$6$ 6$ 	6$ 6$ 6$ 6$ (6$ 
46$|  $*7:E:E:E :E 	:E :E :E (:E 
:EB  $


 

 
 
 

<  $*<0)0)0) 0) 	0)
 0) 0) 0) (0) 
0)p  $*< ? ? ?  ?
  ?  ?  ? ( ? 
 ?D$HL!
!
!
 !
 	!

 !
 (!
 
*!
r   r   ) __doc__
__future__r   r   rK   argparser   	functoolsr   typesr   typingr   r   r	   r
   r   r   r   r   r9   r   r   r   r}   r    r   RuntimeErrorr   r   
deprecatedr   r   r   <module>r      sx    ( " 
      2>>)A#AT&\:J 	l 	@
 @
F  ,
r   