
    wBf:                       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d	 	 	 	 	 	 	 	 	 	 	 ddZd
d
dd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	d
dd	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
d
dd	 	 	 	 	 	 	 	 	 	 	 ddZd
dd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZd
dd	 	 	 	 	 	 	 	 	 	 	 	 	 ddZd dZed	 	 	 	 	 	 	 	 	 	 	 	 	 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     JtTJs   .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stackc               $     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=   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>.innerp   s'    gxAIFT,V,,r   rL   zP.argsrM   zP.kwargsreturnr   _generate_messager   r   r   r   )	rO   rQ   rN   rP   r=   rB   rC   r'   r>   s	   ` @@r   deprecated_decoratorz9DeprecationHandler.__call__.<locals>.deprecated_decoratorb   so     $ 6 6)#//*!D,=,=+>?!	 !7 !Hg %g.. 4[- -
 Lr   rO   Callable[P, T]rS   rX   r   )r'   rB   rC   r=   r>   rV   s   ````` r   __call__zDeprecationHandler.__call__R   s     	 	, $#r   )renamer=   r>   c               ,     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.rA   c                     |v rAt        j                  dz          |j                  d       }r|j                  |        | i |S rF   )rJ   rK   pop
setdefault)	rL   rM   valueargumentrN   rO   rP   rZ   r>   s	      r   rQ   zHDeprecationHandler.argument.<locals>.deprecated_decorator.<locals>.inner   sV     v%MM'8E	J #JJx6E))&%8T,V,,r   rR   rT   )rO   rQ   rN   rP   r=   rc   rB   rC   rZ   r'   r>   s   ` @@r   rV   z9DeprecationHandler.argument.<locals>.deprecated_decorator   s     $ 6 6)#//*!D,=,=+>azK 39eF8:.x !7 !Hg %g.. 4[
- 
- 
- Lr   rW   r   )r'   rB   rC   rc   rZ   r=   r>   rV   s   ``````` r   rc   zDeprecationHandler.argumentz   s    (	 	@ $#r   c               h      G  fddt               }t        |j                  ||fi       S )z9Wraps any argparse.Action to issue a deprecation warning.c                  h     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]rN   strhelpc                    t        |   |i | 	j                  | j                  rd| j                  d    dnd| j                   dt
              \  }}|st        |      || _        || _        y )N`)rB   rC   rD   r=   deprecation_type)	superr)   rU   option_stringsdestFutureWarningr   rN   ri   )

inner_selfrL   rM   rN   rP   	__class__r=   rB   rC   r'   s
        r   r)   z<DeprecationHandler.action.<locals>.DeprecationMixin.__init__   s     $1&1$($:$:!-'
 &44 J55b9:!<  ! 13%%2 %; %!'   )'22&.
#")
r   c                    t        j                  | j                  | j                  dz          t        |   ||||       y )N   rH   )rJ   rK   ri   rN   rn   rY   )rr   parser	namespacevaluesoption_stringrs   r>   s        r   rY   z<DeprecationHandler.action.<locals>.DeprecationMixin.__call__   s=     OO'' 5y  FMJr   )rr   r   rL   r
   rM   r
   rS   Noner,   )rr   r   rv   r   rw   r	   rx   r
   ry   r    rS   rz   )r   r   r   __annotations__r)   rY   __classcell__)rs   r=   rB   rC   r'   r>   s   @r   DeprecationMixinrf      sg    ##I* *< -1K K&K %K 	K
  *K K Kr   r}   )r   typer   )r'   rB   rC   actionr=   r>   r}   s   ``` `` r   r   zDeprecationHandler.action   s3    +	K +	Kv +	KZ FOO&6%?DDr   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   rG   )rB   rC   topicr=   r>   N)r   _get_module)r'   rB   rC   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   rA   __getattr__Nc                    | k(  rt        j                  dz          S r |       S t        d d|  d      )NrG   rH   zmodule 'z' has no attribute '')rJ   rK   r5   )namerN   constantfullnamerP   r>   super_getattrrb   s    r   r   z0DeprecationHandler.constant.<locals>.__getattr__%  sM    xgxAIF$T** 8H:5I$q!QRRr   )r   rh   rS   r
   )r   rU   r   getattrr   )r'   rB   rC   r   rb   r=   r>   r   r   rN   r   rP   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.
        rA   rG   rH   N)rU   r   rJ   rK   )r'   rB   rC   r   r=   r>   rN   rP   s           r   r   zDeprecationHandler.topic1  sP    $ !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.
        rG   __file__r   Nz&unable to determine the calling module)sys	_getframef_codeco_filenamer2   modulesrx   
isinstancer   hasattrr   r   r5   inspect	getmodule
IndexErrorr   )r'   r>   framefilenameloadedr   r   s          r   r   zDeprecationHandler._get_moduleQ  s    	1MM!e),E9 <<33 $CKK$6$6$89 9F%fj9 "6:6 (2 &889 &&u-F!00FGG+ "   	4 FGG9	s"   C C 	CC	C0/C0)rm   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'   rB   rC   rD   r=   rm   rN   warnings           r   rU   z$DeprecationHandler._generate_messagew  s    ( ""<00HFykQRSG$$Y/'H=i[JGH29+Q?G HHVD67H"=>?
 	
r   )r'   r   r(   rh   rS   rz   )r(   rh   rS   r"   )r'   r   r(   rh   rS   bool)r'   r   rB   rh   rC   rh   r=   r    r>   r-   rS   *Callable[[Callable[P, T]], Callable[P, T]])r'   r   rB   rh   rC   rh   rc   rh   rZ   r    r=   r    r>   r-   rS   r   )r'   r   rB   rh   rC   rh   r   r   r=   r    r>   r-   rS   r   )r'   r   rB   rh   rC   rh   r=   r    r>   r-   rS   rz   )r'   r   rB   rh   rC   rh   r   rh   rb   r
   r=   r    r>   r-   rS   rz   )r'   r   rB   rh   rC   rh   r   rh   r=   r    r>   r-   rS   rz   )r'   r   r>   r-   rS   ztuple[ModuleType, str])r'   r   rB   rh   rC   rh   rD   rh   r=   r    rm   rg   rS   z tuple[type[Warning] | None, str])r   r   r   r{   r)   staticmethodr&   r<   rY   rc   r   r   r   r   r   DeprecationWarningrU   r   r   r   r   r   "   so   **##	$  54  $&$&$&$ &$
 &$ &$ 
4&$\ "#4$4$4$ 4$ 	4$ 4$ 4$ 4$ 
44$x  $8E8E8E 8E 	8E 8E 8E 
8E~  $


 

 
 
 

<  $.).).) .) 	.)
 .) .) .) 
.)l  $??? ?
 ? ? ? 
?@$HZ +=!
!
!
 !
 	!

 !
 (!
 
*!
r   r   ) __doc__
__future__r   r   rJ   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 	v
 v
r  ,
r   