
    q-Ph5                       U d dl mZ d dl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 d dlmZmZmZmZmZ d dlmZ ej        d	k    rd d
lmZ n	 d d
lmZ n# e$ r d:dZY nw xY wd dlmZ er:d dlmZ ej        dk    rd dlmZ nd dlmZ d dlmZ  ed          Z ed          Z dddZ!de"d<   ddd;d Z#d:d!Z$d<d"Z%d=d%Z&d>d)Z'	 d?d@d-Z(dAd/Z)dBd0Z*dCd4Z+dDd8Z,g d9Z-dS )E    )annotationsN)defaultdict)Sequence)wraps)Path)TYPE_CHECKINGAnyCallableTypeVarget_args)DeprecationType)      )
deprecatedmessagestrreturn*Callable[[Callable[P, T]], Callable[P, T]]c                     t          |           S N)_deprecate_function)r   s    Y/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/polars/_utils/deprecation.pyr   r      s     'w///    )issue_warning)Mapping)r   
   )	ParamSpec)	AmbiguousPTearliestlatest)TFzMapping[bool, Ambiguous]USE_EARLIEST_TO_AMBIGUOUS versionr&   Nonec               h    |r|                                   d| d} t          | t                     dS )a  
    Issue a deprecation warning.

    Parameters
    ----------
    message
        The message associated with the warning.
    version
        The version in which deprecation occurred
        (if the version number was not already included in `message`).
    z
(Deprecated in version )N)stripr   DeprecationWarning)r   r&   s     r   issue_deprecation_warningr,   /   sB      J]]__IIwIII'-.....r   c                     d fd}|S )z+Decorator to mark a function as deprecated.functionCallable[P, T]r   c                     t                     d fd            }t          j                   |_        |_        |S )	NargsP.argskwargsP.kwargsr   r    c                 2    t                      | i |S r   r,   )r1   r3   r.   r   s     r   wrapperz6_deprecate_function.<locals>.decorate.<locals>.wrapperD   s&    %g...8T,V,,,r   r1   r2   r3   r4   r   r    )r   inspect	signature__signature____deprecated__)r.   r7   r   s   ` r   decoratez%_deprecate_function.<locals>.decorateC   sY    	x	- 	- 	- 	- 	- 	- 
	- !( 1( ; ;!(r   r.   r/   r   r/    )r   r=   s   ` r   r   r   @   s(          Or   c                     dd} | S )zJDecorator to mark `streaming` argument as deprecated due to being renamed.r.   r/   r   c                p     t                     d fd            }t          j                   |_        |S )	Nr1   r2   r3   r4   r   r    c                 n    d|v r)t          d           |d         rd|d<   n	d|vrd|d<   |d=  | i |S )N	streamingzIthe `streaming` parameter was deprecated in 1.25.0; use `engine` instead.zold-streamingenginez	in-memoryr6   )r1   r3   r.   s     r   r7   z@deprecate_streaming_parameter.<locals>.decorate.<locals>.wrapperT   sq    f$$)_   +& 3'6F8$$V++'2F8$;'8T,V,,,r   r8   r   r9   r:   r;   )r.   r7   s   ` r   r=   z/deprecate_streaming_parameter.<locals>.decorateS   sK    	x	- 	- 	- 	- 	- 
	- !( 1( ; ;r   r>   r?   )r=   s    r   deprecate_streaming_parameterrF   P   s       & Or   old_namenew_namec                    d fd}|S )a  
    Decorator to mark a function parameter as deprecated due to being renamed.

    Use as follows:

        @deprecate_renamed_parameter("old_name", new_name="new_name")
        def myfunc(new_name): ...

    Ensure that you also update the function docstring with a note about the
    deprecation, specifically adding a `.. versionchanged:: 0.0.0` directive
    that states which parameter was renamed to which new name and in which
    version the rename happened.
    r.   r/   r   c                x     t                     d fd            }t          j                   |_        |S )	Nr1   r2   r3   r4   r   r    c                 D    t          |j                    | i |S r   )_rename_keyword_argument__qualname__)r1   r3   r.   rH   rG   r&   s     r   r7   z>deprecate_renamed_parameter.<locals>.decorate.<locals>.wrapper{   s:    $(FH,A7   8T,V,,,r   r8   rE   )r.   r7   rH   rG   r&   s   ` r   r=   z-deprecate_renamed_parameter.<locals>.decoratez   s[    	x	- 	- 	- 	- 	- 	- 	- 	- 
	- !( 1( ; ;r   r>   r?   )rG   rH   r&   r=   s   ``` r   deprecate_renamed_parameterrN   i   s4    "	 	 	 	 	 	 	 	 Or   r3   dict[str, object]	func_namec                    | |v rp||v r-|rd| nd}d|d| d|d| d| d|d	}t          |          |rd
| nd}t          d|  d| d| d| d	           |                    |           ||<   dS dS )z(Rename a keyword argument of a function.zwas deprecated in version zis deprecated`z` received both `z` and `z` as arguments; `z` z, use `z	` insteadz in version r$   zthe argument `z` for `z$` is deprecated. It was renamed to `.N)	TypeErrorr,   pop)rG   rH   r3   rP   r&   is_deprecatedmsg
in_versions           r   rL   rL      s7    6v:AV6W666 OI O O( O OX O OO O#0O O9AO O O  C.. 18@-G---b
!;X ; ;i ; ;"*; ;-7; ; ;	
 	
 	
 "::h//x! r   allowed_argslist[str] | None
str | Nonec                    d fd}|S )a  
    Decorator for deprecating the use of non-keyword arguments in a function.

    Use as follows:

        @deprecate_nonkeyword_arguments(allowed_args=["self", "val"], version="1.0.0")
        def myfunc(self, val: int = 0, other: int: = 0): ...

    Ensure that you also update the function docstring with a note about the
    deprecation, specifically adding a `.. versionchanged:: 0.0.0` directive
    that states that we now expect keyword args and in which version this
    update happened.

    Parameters
    ----------
    allowed_args
        The names of some first arguments of the decorated function that are allowed to
        be given as positional arguments. Should include "self" when decorating class
        methods. If set to None (default), equal to all arguments that do not have a
        default value.
    message
        Optionally overwrite the default warning message.
    version
        The Polars version number in which the warning is first issued.
    r.   r/   r   c                    t          j                   }		n#d |j                                        D             fd|j                                        D             }|                    d            |                    |          }t                    
/d j         d}|                    t                              n
t                     d fd            }||_        |S )Nc                b    g | ],}|j         |j        |j        fv r|j        |j        u %|j        -S r?   )kindPOSITIONAL_ONLYPOSITIONAL_OR_KEYWORDdefaultemptyname).0ps     r   
<listcomp>zDdeprecate_nonkeyword_arguments.<locals>.decorate.<locals>.<listcomp>   sM       6a/1HIIII((  )((r   c                    g | ]=}|j         |j        |j        fv r$|j        vr|                    |j                   n|>S )r_   )r_   r`   ra   rd   replaceKEYWORD_ONLY)re   rf   
allow_argss     r   rg   zDdeprecate_nonkeyword_arguments.<locals>.decorate.<locals>.<listcomp>   sj     
 
 
 	 1,a.EFFFF*,, II1>I***
 
 
 
r   c                    | j         S r   ri   )rf   s    r   <lambda>zBdeprecate_nonkeyword_arguments.<locals>.decorate.<locals>.<lambda>   s    af r   )key)
parameterszall arguments of zo{except_args} will be keyword-only in the next breaking release. Use keyword arguments to silence this warning.)except_argsr1   r2   r3   r4   r   r    c                 \    t          |           k    rt                      | i |S )Nr%   )lenr,   )r1   r3   r.   rW   num_allowed_argsr&   s     r   r7   zAdeprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper   s=    4yy+++)#w????8T,V,,,r   r8   )r9   r:   rp   valuessortrj   rs   rM   format_format_argument_listr   r;   )r.   old_sig
new_paramsnew_sig
msg_formatr7   rl   rW   rt   rY   r   r&   s   `     @@@r   r=   z0deprecate_nonkeyword_arguments.<locals>.decorate   s^   #H--#%JJ  +2244  J
 
 
 
 '..00
 
 

 	,,---//Z/88z???BH$9 B B B  ##0Ej0Q0Q#RRCCC	x	- 	- 	- 	- 	- 	- 	- 	- 
	-
 !(r   r>   r?   )rY   r   r&   r=   s   ``` r   deprecate_nonkeyword_argumentsr}      s5    :+ + + + + + + +Z Or   	list[str]c                    d| v r|                      d           | sdS t          |           dk    rd| d         S | d         }d                    d | d	d         D                       }d| d
|S )zaFormat allowed arguments list for use in the warning message of `deprecate_nonkeyword_arguments`.selfr$      z except for r   z, c                    g | ]}|S r?   r?   )re   xs     r   rg   z)_format_argument_list.<locals>.<listcomp>   s    >>>qQ(>>>r   Nz and )removers   join)rY   lastr1   s      r   rx   rx      s    F### 2r	\		a		1l1o111Byy>>L",=>>>??1d11111r   c                     d fd}|S )a  
    Decorator to mark a function argument as deprecated due to being made multi-positional.

    Use as follows:

        @deprecate_parameter_as_multi_positional("columns")
        def myfunc(*columns): ...

    Ensure that you also update the function docstring with a note about the
    deprecation, specifically adding a `.. versionchanged:: 0.0.0` directive
    that states that we now expect positional args and in which version this
    update happened.
    r.   r/   r   c                t     t                     d fd            }t          j                   |_        |S )	Nr1   r2   r3   r4   r   r    c                 F   	 |                               }n# t          $ r  | i |cY S w xY wt          d d           t          |t                    rt          |t
                    r|f}n$t          |t                    st          |          }| |z   }  | i |S )Nz	passing `zP` as a keyword argument is deprecated. Pass it as a positional argument instead.)rU   KeyErrorr,   
isinstancer   r   tuple)r1   r3   	arg_valuer.   rG   s      r   r7   zJdeprecate_parameter_as_multi_positional.<locals>.decorate.<locals>.wrapper  s    1"JJx00		 1 1 1x0000001 &=H = = =  
 i22 -jC6P6P -&L			511 -!),,	)#D8T,V,,,s    ..r8   rE   )r.   r7   rG   s   ` r   r=   z9deprecate_parameter_as_multi_positional.<locals>.decorate  sQ    	x	- 	- 	- 	- 	- 	- 
	-& !( 1( ; ;r   r>   r?   )rG   r=   s   ` r   'deprecate_parameter_as_multi_positionalr      s(    "     0 Or   sourcemodule_pathdefaultdict[str, list[str]]c                    t          j        |           }g d
fddfdt          t                     G fdd	t           j                  } |                                |           S )N	decoratorr	   r   r   c                    t          | t          j                  rd| j        v r| j        ndS t          | t          j                  r | j                  S dS )N	deprecater$   )r   astNameidCallfunc)r   r   s    r   r   z._find_deprecated_functions.<locals>.deprecated0  sZ    i** 	.#.),#>#>9<<BF	38,, 	.:in---rr   rP   c                8    d                     g|           S )NrS   )r   )rP   r   object_paths    r   qualified_namez2_find_deprecated_functions.<locals>.qualified_name7  s"    xx>{>I>???r   c                  0    e Zd ZdfdZd fdZeZdS )	3_find_deprecated_functions.<locals>.FunctionVisitornoder	   r   r'   c                                         |j                   |                     |                                            d S r   )appendrd   generic_visitrU   )r   r   r   s     r   visit_ClassDefzB_find_deprecated_functions.<locals>.FunctionVisitor.visit_ClassDef=  sC    ty)))t$$$OOr   c                   t          fd|j        D                       rR                    d                              dd          }|                              |j                             |                     |           d S )Nc              3  2   K   | ]} |          xV  d S r   r?   )re   ddecorator_namer   s     r   	<genexpr>zX_find_deprecated_functions.<locals>.FunctionVisitor.visit_FunctionDef.<locals>.<genexpr>C  s0      RRjjmm3NRRRRRRr   
deprecate_r   r.   )anydecorator_listremoveprefixrj   r   rd   r   )r   r   ro   r   r   r   resultss      @r   visit_FunctionDefzE_find_deprecated_functions.<locals>.FunctionVisitor.visit_FunctionDefB  s    RRRRRd>QRRRRR ?$11,??GG *  ##NN49$=$=>>>t$$$$$r   N)r   r	   r   r'   )__name__
__module__rM   r   r   visit_AsyncFunctionDef)r   r   r   r   s   r   FunctionVisitorr   <  s_        	 	 	 	 	 	
	% 	% 	% 	% 	% 	% 	% 	% "3r   r   )r   r	   r   r   )rP   r   r   r   )r   parser   listNodeVisitorvisit)r   r   treer   r   r   r   r   s    `  @@@@r   _find_deprecated_functionsr   *  s     9VDK     @ @ @ @ @ @ @ $G3 3 3 3 3 3 3 3 3 3#/ 3 3 3  OD!!!Nr   typesr   dict[str, list[str]]c            	     p    t          t          t                              } D ]?}||vr9d|dt          t	          |                    dd          }t          |          @t          t          j        d         j	                  j
        }t          t                    |                    d          D ]}|                    |          }d                    |j                                      d          }|                    d	d
          5 }t'          |                                |                                          D ]9\  }	}
|	|vrd|d}t          |          |	                             |
           :	 ddd           n# 1 swxY w Y    fdt	                    D             S )a  
    Return a dict identifying functions/methods that are deprecated in some way.

    Parameters
    ----------
    *types
        The types of deprecations to identify.
        If empty, all types are returned; recognised values are:
            - "function"
            - "renamed_parameter"
            - "streaming_parameter"
            - "nonkeyword_arguments"
            - "parameter_as_multi_positional"

    Examples
    --------
    >>> from polars._utils.deprecation import identify_deprecations
    >>> identify_deprecations("streaming_parameter")  # doctest: +IGNORE_RESULT
    {'streaming_parameter': [
        'functions.lazy.collect_all',
        'functions.lazy.collect_all_async',
        'lazyframe.frame.LazyFrame.collect',
        'lazyframe.frame.LazyFrame.collect_async',
        'lazyframe.frame.LazyFrame.explain',
        'lazyframe.frame.LazyFrame.show_graph',
    ]}
    zunrecognised deprecation type z.
Expected one (or more) of r   r   polarsz*.pyrS   z.pyrzutf-8)encoding)r   r   z.
Nc                H    i | ]}r|v |t          |                   S r?   )sorted)re   depr   r   s     r   
<dictcomp>z)identify_deprecations.<locals>.<dictcomp>  sB        u 	VGCL!!$r   )setr   r   reprr   
ValueErrorr   sysmodules__file__parentr   r   rglobrelative_tor   partsremovesuffixopenr   readitemsextend)r   valid_typestprW   package_pathpy_filerel_pathr   srcdeprecation_type
func_namesr   s   `          @r   identify_deprecationsr   P  s-   8 h//00K " "[  O O O-1&2E2E-F-Fqt-LO O  S//! ! H-677>L$G%%f-- = =&&|44hhx~..;;EBB\\#\00 	=C0Jxxzz'1 1 1 egg
= 
=, * $;66 E2DDDC$S//)()00<<<<
=	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=    '??   s   A0FF	F	)r}   r   rN   rF   r   r   )r   r   r   r   )r   r   r&   r   r   r'   )r   r   )rG   r   rH   r   r&   r   r   r   )rG   r   rH   r   r3   rO   rP   r   r&   r   r   r'   )NN)rY   rZ   r   r[   r&   r   r   r   )rY   r~   r   r   )rG   r   r   r   )r   r   r   r   r   r   )r   r   r   r   ).
__future__r   r   r9   r   collectionsr   collections.abcr   	functoolsr   pathlibr   typingr   r	   r
   r   r   polars._typingr   version_infowarningsr   typing_extensionsImportErrorpolars._utils.variousr   r   r   r   r   r    r#   __annotations__r,   r   rF   rN   rL   r}   rx   r   r   r   __all__r?   r   r   <module>r      s   " " " " " " " 



  



 # # # # # # $ $ $ $ $ $             B B B B B B B B B B B B B B * * * * * *w#######00000000 0 0 0	0 	0 	0 	0 	0 	00 0 / / / / / 
''''''
7""$$$$$$$//////((((((	#AA 7 7      ?A / / / / / /"       2   >0 0 0 08 BFJ J J J JZ2 2 2 2) ) ) )X# # # #L< < < <~  s   A 	A&%A&